@rbxts/centurion-ui 1.0.0-dev-e01f578 → 1.0.0-dev-a7b773c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
2
  <a href="https://centurion.paradoxum.dev/" target="_blank">
3
- <img src="../../docs/src/assets/logo.webp" width="150" />
3
+ <img src="https://raw.githubusercontent.com/paradoxuum/centurion/main/docs/src/assets/logo.webp" width="150" />
4
4
  </a>
5
5
 
6
6
  <h1>Centurion - UI</h1>
@@ -26,4 +26,4 @@
26
26
  <a href="https://centurion.paradoxum.dev/">📖 Documentation</a>
27
27
  </div>
28
28
 
29
- <img src="../../public/banner.png" />
29
+ <img src="https://raw.githubusercontent.com/paradoxuum/centurion/main/public/banner.png" />
@@ -7,6 +7,7 @@ local subscribe = TS.import(script, TS.getModule(script, "@rbxts", "charm").src)
7
7
  local UserInputService = TS.import(script, TS.getModule(script, "@rbxts", "services")).UserInputService
8
8
  local _vide = TS.import(script, TS.getModule(script, "@rbxts", "vide").src)
9
9
  local Vide = _vide
10
+ local cleanup = _vide.cleanup
10
11
  local effect = _vide.effect
11
12
  local source = _vide.source
12
13
  local getAPI = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-api").getAPI
@@ -14,8 +15,6 @@ local useAtom = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-ato
14
15
  local useEvent = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-event").useEvent
15
16
  local px = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-px").px
16
17
  local _store = TS.import(script, script.Parent.Parent.Parent, "store")
17
- local commandHistory = _store.commandHistory
18
- local commandHistoryIndex = _store.commandHistoryIndex
19
18
  local currentArgIndex = _store.currentArgIndex
20
19
  local currentCommandPath = _store.currentCommandPath
21
20
  local currentSuggestion = _store.currentSuggestion
@@ -42,6 +41,8 @@ local function TerminalTextField(_param)
42
41
  local visible = useAtom(interfaceVisible)
43
42
  local valid = useAtom(terminalTextValid)
44
43
  local ref = source(nil)
44
+ local commandHistory = source({})
45
+ local commandHistoryIndex = source(nil)
45
46
  local text = source("")
46
47
  local suggestionText = source("")
47
48
  -- Focus text field when terminal becomes visible
@@ -64,16 +65,22 @@ local function TerminalTextField(_param)
64
65
  return nil
65
66
  end
66
67
  local historyIndex = commandHistoryIndex()
67
- if (up and historyIndex == 0) or (not up and historyIndex == -1) then
68
+ if not up and historyIndex == nil then
68
69
  return nil
69
70
  end
70
- local newIndex
71
- if up then
72
- newIndex = if historyIndex == -1 then #history - 1 else historyIndex - 1
73
- else
74
- newIndex = if historyIndex ~= #history - 1 then historyIndex + 1 else -1
71
+ local lastIndex = #history - 1
72
+ if not up and historyIndex == lastIndex then
73
+ text("")
74
+ suggestionText("")
75
+ commandHistoryIndex(nil)
76
+ return nil
77
+ end
78
+ local _condition = historyIndex
79
+ if _condition == nil then
80
+ _condition = #history
75
81
  end
76
- local newText = if newIndex ~= -1 then history[newIndex + 1] else ""
82
+ local newIndex = math.clamp(_condition + (if up then -1 else 1), 0, lastIndex)
83
+ local newText = history[newIndex + 1]
77
84
  text(newText)
78
85
  suggestionText("")
79
86
  commandHistoryIndex(newIndex)
@@ -82,7 +89,7 @@ local function TerminalTextField(_param)
82
89
  textBox.CursorPosition = #newText + 1
83
90
  end
84
91
  end
85
- subscribe(currentSuggestion, function(suggestion)
92
+ local suggestionConnection = subscribe(currentSuggestion, function(suggestion)
86
93
  if suggestion == nil then
87
94
  suggestionText("")
88
95
  return nil
@@ -113,6 +120,7 @@ local function TerminalTextField(_param)
113
120
  end
114
121
  suggestionText(newText)
115
122
  end)
123
+ cleanup(suggestionConnection)
116
124
  useEvent(UserInputService.InputBegan, function(input)
117
125
  local textBox = ref()
118
126
  local _condition = textBox == nil
@@ -276,17 +284,15 @@ local function TerminalTextField(_param)
276
284
  local currentText = textBox.Text
277
285
  local history = commandHistory()
278
286
  if currentText ~= "" and (#history == 0 or history[#history] ~= currentText) then
279
- commandHistory(function(prev)
280
- local _array = {}
281
- local _length = #_array
282
- local _prevLength = #prev
283
- table.move(prev, 1, _prevLength, _length + 1, _array)
284
- _length += _prevLength
285
- _array[_length + 1] = textBox.Text
286
- return _array
287
- end)
287
+ local _array = {}
288
+ local _length = #_array
289
+ local _historyLength = #history
290
+ table.move(history, 1, _historyLength, _length + 1, _array)
291
+ _length += _historyLength
292
+ _array[_length + 1] = textBox.Text
293
+ commandHistory(_array)
288
294
  end
289
- commandHistoryIndex(-1)
295
+ commandHistoryIndex(nil)
290
296
  local _result = onSubmit
291
297
  if _result ~= nil then
292
298
  _result(currentText)
@@ -295,7 +301,10 @@ local function TerminalTextField(_param)
295
301
  text("")
296
302
  end,
297
303
  textChanged = function(currentText)
298
- commandHistoryIndex(-1)
304
+ local historyIndex = commandHistoryIndex()
305
+ if historyIndex ~= nil and currentText ~= commandHistory()[historyIndex + 1] then
306
+ commandHistoryIndex(nil)
307
+ end
299
308
  text(currentText)
300
309
  end,
301
310
  zIndex = 2,
package/out/store.d.ts CHANGED
@@ -5,8 +5,6 @@ export declare const interfaceOptions: import("@rbxts/charm").Atom<InterfaceOpti
5
5
  export declare const mouseOverInterface: import("@rbxts/charm").Atom<boolean>;
6
6
  export declare const currentCommandPath: import("@rbxts/charm").Atom<ImmutableRegistryPath | undefined>;
7
7
  export declare const currentArgIndex: import("@rbxts/charm").Atom<number | undefined>;
8
- export declare const commandHistory: import("@rbxts/charm").Atom<string[]>;
9
- export declare const commandHistoryIndex: import("@rbxts/charm").Atom<number>;
10
8
  export declare const currentSuggestion: import("@rbxts/charm").Atom<Suggestion | undefined>;
11
9
  export declare const terminalText: import("@rbxts/charm").Atom<string>;
12
10
  export declare const terminalTextParts: import("@rbxts/charm").Molecule<string[]>;
package/out/store.lua CHANGED
@@ -10,8 +10,6 @@ local interfaceOptions = atom(DEFAULT_INTERFACE_OPTIONS)
10
10
  local mouseOverInterface = atom(false)
11
11
  local currentCommandPath = atom(nil)
12
12
  local currentArgIndex = atom(nil)
13
- local commandHistory = atom({})
14
- local commandHistoryIndex = atom(-1)
15
13
  local currentSuggestion = atom(nil)
16
14
  local terminalText = atom("")
17
15
  local terminalTextParts = computed(function()
@@ -34,8 +32,6 @@ return {
34
32
  mouseOverInterface = mouseOverInterface,
35
33
  currentCommandPath = currentCommandPath,
36
34
  currentArgIndex = currentArgIndex,
37
- commandHistory = commandHistory,
38
- commandHistoryIndex = commandHistoryIndex,
39
35
  currentSuggestion = currentSuggestion,
40
36
  terminalText = terminalText,
41
37
  terminalTextParts = terminalTextParts,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rbxts/centurion-ui",
3
3
  "description": "Terminal UI for the Centurion command framework",
4
- "version": "1.0.0-dev-e01f578",
4
+ "version": "1.0.0-dev-a7b773c",
5
5
  "author": "paradoxuum",
6
6
  "license": "MIT",
7
7
  "main": "out/init.lua",
@@ -32,7 +32,7 @@
32
32
  "dev": "shx rm -rf out && rbxtsc -w"
33
33
  },
34
34
  "devDependencies": {
35
- "@rbxts/centurion": "^1.0.0-dev-e01f578",
35
+ "@rbxts/centurion": "^1.0.0-dev-a7b773c",
36
36
  "@rbxts/compiler-types": "2.3.0-types.1",
37
37
  "@rbxts/types": "^1.0.790",
38
38
  "roblox-ts": "2.3.0-dev-26ec859",
@@ -47,7 +47,7 @@
47
47
  "@rbxts/vide": "^0.4.1"
48
48
  },
49
49
  "peerDependencies": {
50
- "@rbxts/centurion": "^1.0.0-dev-e01f578"
50
+ "@rbxts/centurion": "^1.0.0-dev-a7b773c"
51
51
  },
52
52
  "stableVersion": "1.0.0"
53
53
  }