@rbxts/centurion-ui 2.0.0-rc.1 → 2.0.0-rc.3

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/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": "2.0.0-rc.1",
4
+ "version": "2.0.0-rc.3",
5
5
  "author": "paradoxuum",
6
6
  "license": "MIT",
7
7
  "main": "src/ts/init.luau",
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@rbxts/centurion": "^2.0.0-rc.1"
36
+ "@rbxts/centurion": "^2.0.0-rc.2"
37
37
  },
38
38
  "scripts": {}
39
39
  }
@@ -9,12 +9,16 @@ local preferred_input = require("../input")
9
9
  local px = require("../px")
10
10
  local state = require("../state")
11
11
  local text = require("../components/text")
12
+ local theme = require("../theme")
12
13
  local vide = require("../../vide")
13
14
 
15
+ local create = vide.create
14
16
  local show = vide.show
17
+ local source = vide.source
15
18
 
16
19
  type Header = {
17
20
  read order: number?,
21
+ read on_clear: () -> (),
18
22
  }
19
23
 
20
24
  -- KeyCode names that aren't what's printed on the key
@@ -37,21 +41,62 @@ local function key_label(key: Enum.KeyCode): string
37
41
  return key_labels[key.Name] or key.Name
38
42
  end
39
43
 
44
+ local function clear_button(props: { order: number, on_clear: () -> () })
45
+ local hovered = source(false)
46
+
47
+ return create "TextButton" {
48
+ AutomaticSize = Enum.AutomaticSize.XY,
49
+ AutoButtonColor = false,
50
+ BackgroundTransparency = 1,
51
+ LayoutOrder = props.order,
52
+ Text = "",
53
+
54
+ Activated = props.on_clear,
55
+ MouseEnter = function()
56
+ hovered(true)
57
+ end,
58
+ MouseLeave = function()
59
+ hovered(false)
60
+ end,
61
+
62
+ text {
63
+ auto = "XY",
64
+ text = "Clear",
65
+ text_size = px(state.subtext_size),
66
+ text_style = function()
67
+ return if hovered() then "highlight" else "subtext"
68
+ end,
69
+ weight = Enum.FontWeight.Bold,
70
+ },
71
+ }
72
+ end
73
+
40
74
  local function header(props: Header)
41
75
  local input = preferred_input()
42
76
 
77
+ local function show_clear()
78
+ return state.clear_button() and #state.logs() > 0
79
+ end
80
+
81
+ local function show_hint()
82
+ if input() == Enum.PreferredInput.Gamepad then
83
+ return true
84
+ end
85
+ return input() == Enum.PreferredInput.KeyboardAndMouse and #state.activation_keys() > 0
86
+ end
87
+
43
88
  return container {
44
- size = px(UDim2.new(1, 0, 0, 34)),
89
+ size = px(UDim2.new(1, 0, 0, 23)),
45
90
  order = props.order,
46
91
 
47
- padding { x = px(12) },
92
+ padding { x = px(8) },
48
93
  flex():column():vertical("center"):between("horizontal"),
49
94
 
50
95
  container {
51
96
  auto = "XY",
52
97
  order = 1,
53
98
 
54
- flex():column():vertical("center"):gap(8),
99
+ flex():column():vertical("center"):gap(5),
55
100
 
56
101
  image {
57
102
  image = state.icon,
@@ -77,51 +122,73 @@ local function header(props: Header)
77
122
  },
78
123
  },
79
124
 
80
- show(function()
81
- if input() == Enum.PreferredInput.Gamepad then
82
- return true
83
- end
84
- return input() == Enum.PreferredInput.KeyboardAndMouse and #state.activation_keys() > 0
85
- end, function()
86
- return container {
87
- auto = "XY",
88
- order = 2,
125
+ container {
126
+ auto = "XY",
127
+ order = 2,
89
128
 
90
- flex():column():vertical("center"):gap(6),
129
+ flex():column():vertical("center"):gap(8),
91
130
 
92
- background {
93
- auto = "XY",
94
- order = 1,
131
+ -- only shown while there's something to clear
132
+ show(show_clear, function()
133
+ return clear_button { order = 1, on_clear = props.on_clear }
134
+ end),
135
+
136
+ -- vertical rule between the clear button and the close hint
137
+ show(function()
138
+ return show_clear() and show_hint()
139
+ end, function()
140
+ return background {
141
+ order = 2,
142
+ size = px(function()
143
+ return UDim2.fromOffset(1, state.subtext_size())
144
+ end),
95
145
  color = function()
96
- return state.theme().surface
146
+ return theme.border(state.theme())
97
147
  end,
148
+ }
149
+ end),
98
150
 
99
- corner(px(4)),
100
- padding { x = px(6), y = px(2) },
151
+ show(show_hint, function()
152
+ return container {
153
+ auto = "XY",
154
+ order = 3,
101
155
 
102
- text {
156
+ flex():column():vertical("center"):gap(4),
157
+
158
+ background {
103
159
  auto = "XY",
104
- text = function()
105
- -- gamepads close with B rather than an activation key
106
- if input() == Enum.PreferredInput.Gamepad then
107
- return button_name(Enum.KeyCode.ButtonB)
108
- end
109
- return key_label(state.activation_keys()[1])
160
+ order = 1,
161
+ color = function()
162
+ return state.theme().surface
110
163
  end,
111
- text_size = px(state.subtext_size),
112
- weight = Enum.FontWeight.Bold,
164
+
165
+ corner(px(4)),
166
+ padding { x = px(4), y = px(1) },
167
+
168
+ text {
169
+ auto = "XY",
170
+ text = function()
171
+ -- gamepads close with B rather than an activation key
172
+ if input() == Enum.PreferredInput.Gamepad then
173
+ return button_name(Enum.KeyCode.ButtonB)
174
+ end
175
+ return key_label(state.activation_keys()[1])
176
+ end,
177
+ text_size = px(state.subtext_size),
178
+ weight = Enum.FontWeight.Bold,
179
+ },
113
180
  },
114
- },
115
181
 
116
- text {
117
- auto = "XY",
118
- order = 2,
119
- text = "to close",
120
- text_size = px(state.subtext_size),
121
- text_style = "subtext",
122
- },
123
- }
124
- end),
182
+ text {
183
+ auto = "XY",
184
+ order = 2,
185
+ text = "to close",
186
+ text_size = px(state.subtext_size),
187
+ text_style = "subtext",
188
+ },
189
+ }
190
+ end),
191
+ },
125
192
  }
126
193
  end
127
194
 
@@ -27,9 +27,10 @@ type History = {
27
27
  read order: number?,
28
28
  }
29
29
 
30
- local line_height = 35
30
+ local line_height = 23
31
+ local top_padding = 4
31
32
  -- width of the status glyph column, which the message is indented by
32
- local gutter = 18
33
+ local gutter = 12
33
34
 
34
35
  local function entry(value: () -> types.Log, i: number, on_select: (command: string) -> ())
35
36
  local hovered = source(false)
@@ -65,15 +66,15 @@ local function entry(value: () -> types.Log, i: number, on_select: (command: str
65
66
  return if success() then 1 else 0.88 + 0.12 * enter()
66
67
  end,
67
68
 
68
- corner(px(6)),
69
+ corner(px(4)),
69
70
  padding {
70
71
  left = px(function()
71
- return 8 + 16 * enter()
72
+ return 5 + 12 * enter()
72
73
  end),
73
- right = px(8),
74
- y = px(6),
74
+ right = px(5),
75
+ y = px(4),
75
76
  },
76
- flex():row():fill("horizontal"):gap(2),
77
+ flex():row():fill("horizontal"):gap(1),
77
78
 
78
79
  -- clicking the header puts the command back into the input
79
80
  create "TextButton" {
@@ -192,10 +193,14 @@ local function history(props: History)
192
193
  ScrollingDirection = Enum.ScrollingDirection.Y,
193
194
  LayoutOrder = props.order,
194
195
  Size = spring(function()
195
- return UDim2.fromOffset(0, math.min(content_height(), max_height()))
196
+ local height = content_height()
197
+ if height == 0 then
198
+ return UDim2.new()
199
+ end
200
+ return UDim2.fromOffset(0, math.min(height, max_height()) + px.convert(top_padding))
196
201
  end, 0.1),
197
202
 
198
- ScrollBarThickness = px(4),
203
+ ScrollBarThickness = px(3),
199
204
  ScrollBarImageColor3 = function()
200
205
  return state.theme().subtext
201
206
  end,
@@ -211,12 +216,12 @@ local function history(props: History)
211
216
  hovered(false)
212
217
  end,
213
218
 
214
- padding { x = px(4) },
219
+ padding { x = px(4), top = px(top_padding) },
215
220
 
216
221
  create "UIListLayout" {
217
222
  HorizontalFlex = Enum.UIFlexAlignment.Fill,
218
223
  SortOrder = Enum.SortOrder.LayoutOrder,
219
- Padding = px(UDim.new(0, 2)),
224
+ Padding = px(UDim.new(0, top_padding)),
220
225
 
221
226
  changed("AbsoluteContentSize", function(size: Vector2)
222
227
  content_height(size.Y)
package/src/app/init.luau CHANGED
@@ -315,9 +315,11 @@ local function app()
315
315
  end)
316
316
 
317
317
  local function submit(value: string)
318
+ local trimmed = value:gsub("^%s*(.-)%s*$", "%1")
319
+
318
320
  -- resolve from the submitted text rather than the analysis, which only
319
321
  -- carries arguments when the cursor happens to sit on one
320
- local submitted = centurion.resolve_command(value)
322
+ local submitted = centurion.resolve_command(trimmed)
321
323
  raw_text("")
322
324
  analysis(default_analysis)
323
325
 
@@ -334,11 +336,16 @@ local function app()
334
336
  end
335
337
 
336
338
  cmd_history_index = 0
337
- table.insert(cmd_history, 1, value)
339
+
340
+ local history_index = table.find(cmd_history, trimmed)
341
+ if history_index ~= nil then
342
+ table.remove(cmd_history, history_index)
343
+ end
344
+ table.insert(cmd_history, 1, trimmed)
338
345
 
339
346
  local cmd = submitted.name
340
347
  if not cmd then
341
- log(value, {
348
+ log(trimmed, {
342
349
  success = false,
343
350
  message = "Unknown command",
344
351
  timestamp = os.time(),
@@ -350,12 +357,12 @@ local function app()
350
357
  executing(executing() + 1)
351
358
 
352
359
  -- pass the submitted text so that ctx.input keeps its original quoting
353
- local ok, result = pcall(centurion.execute_command, Players.LocalPlayer, cmd, submitted.args, value)
360
+ local ok, result = pcall(centurion.execute_command, Players.LocalPlayer, cmd, submitted.args, trimmed)
354
361
  executing(executing() - 1)
355
362
 
356
363
  if not ok then
357
- warn(`Failed to execute '{value}': {result}`)
358
- log(value, {
364
+ warn(`Failed to execute '{trimmed}': {result}`)
365
+ log(trimmed, {
359
366
  success = false,
360
367
  message = "Failed to execute command",
361
368
  timestamp = os.time(),
@@ -365,10 +372,10 @@ local function app()
365
372
 
366
373
  if result.response then
367
374
  if result.response.message ~= "" then
368
- log(value, result.response)
375
+ log(trimmed, result.response)
369
376
  end
370
377
  else
371
- log(value, {
378
+ log(trimmed, {
372
379
  success = true,
373
380
  message = "Command executed",
374
381
  timestamp = os.time(),
@@ -452,11 +459,11 @@ local function app()
452
459
  end,
453
460
  transparency = state.transparency,
454
461
 
455
- corner(px(6)),
462
+ corner(px(4)),
456
463
  padding {
457
- y = px(8),
464
+ y = px(5),
458
465
  left = px(function()
459
- return 34 + shake()
466
+ return 25 + shake()
460
467
  end),
461
468
  right = px(function()
462
469
  return 10 - shake()
@@ -486,7 +493,7 @@ local function app()
486
493
 
487
494
  {
488
495
  AnchorPoint = Vector2.new(0, 0.5),
489
- Position = px(UDim2.new(0, -22, 0.5, 0)),
496
+ Position = px(UDim2.new(0, -15, 0.5, 0)),
490
497
  },
491
498
  },
492
499
 
@@ -545,6 +552,10 @@ local function app()
545
552
  local selected = suggested[selected_suggestion()]
546
553
  value = autofill(raw_text(), selected, true)
547
554
  end
555
+
556
+ if value ~= raw_text() then
557
+ cmd_history_index = 0
558
+ end
548
559
  raw_text(value)
549
560
  end,
550
561
 
@@ -595,16 +606,16 @@ local function app()
595
606
  auto = "Y",
596
607
  anchor = state.anchor,
597
608
  position = function()
598
- local offset = px.convert((reveal() - 1) * 12)
609
+ local offset = px.convert((reveal() - 1) * 8)
599
610
  return px.get(state.position) + UDim2.fromOffset(0, offset)
600
611
  end,
601
612
  size = px(function()
602
613
  local w = state.width()
603
- return UDim2.new(w.Scale, w.Offset, 0, 0)
614
+ return UDim2.new(w.Scale, 1000, 0, 0)
604
615
  end),
605
616
 
606
- padding(px(12)),
607
- flex():row():gap(2),
617
+ padding(px(8)),
618
+ flex():row():gap(1),
608
619
 
609
620
  {
610
621
  Visible = function()
@@ -622,7 +633,7 @@ local function app()
622
633
  end,
623
634
  transparency = state.transparency,
624
635
 
625
- corner(px(10)),
636
+ corner(px(8)),
626
637
  stroke {
627
638
  color = function()
628
639
  return theme.border(state.theme())
@@ -631,7 +642,13 @@ local function app()
631
642
  flex():row():fill("horizontal"),
632
643
  catch_hover(),
633
644
 
634
- header { order = 1 },
645
+ header {
646
+ order = 1,
647
+ on_clear = function()
648
+ state.logs({})
649
+ refocus()
650
+ end,
651
+ },
635
652
  divider { order = 2 },
636
653
 
637
654
  history {
@@ -651,7 +668,7 @@ local function app()
651
668
  size = UDim2.fromScale(1, 0),
652
669
  order = 4,
653
670
 
654
- padding(px(8)),
671
+ padding(px(5)),
655
672
 
656
673
  input_field(),
657
674
  },
@@ -666,9 +683,9 @@ local function app()
666
683
  order = 2,
667
684
 
668
685
  padding {
669
- left = px(8),
686
+ left = px(5),
670
687
  top = px(function()
671
- return 6 * pop()
688
+ return 4 * pop()
672
689
  end),
673
690
  },
674
691
 
@@ -55,7 +55,7 @@ local function pill(props: { text: () -> string, color: () -> Color3, order: num
55
55
  color = props.color,
56
56
 
57
57
  corner(px(4)),
58
- padding { x = px(6), y = px(2) },
58
+ padding { x = px(4), y = px(2) },
59
59
 
60
60
  text {
61
61
  auto = "XY",
@@ -101,7 +101,7 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
101
101
  end,
102
102
 
103
103
  corner(px(4)),
104
- padding { x = px(8), y = px(5) },
104
+ padding { x = px(5), y = px(3) },
105
105
  flex():column():vertical("center"):between("horizontal"),
106
106
 
107
107
  container {
@@ -112,7 +112,7 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
112
112
 
113
113
  -- marks the suggestion Tab will complete
114
114
  text {
115
- size = px(UDim2.fromOffset(18, 0)),
115
+ size = px(UDim2.fromOffset(12, 0)),
116
116
  auto = "Y",
117
117
  order = 1,
118
118
  text = ">",
@@ -165,8 +165,7 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
165
165
  text_style = "subtext",
166
166
  xalignment = Enum.TextXAlignment.Right,
167
167
 
168
- -- keeps the description away from the name
169
- padding { left = px(32) },
168
+ padding { left = px(28) },
170
169
  }
171
170
  end),
172
171
  }
@@ -220,7 +219,7 @@ local function suggestions(props: Suggestions)
220
219
  end,
221
220
  transparency = state.transparency,
222
221
 
223
- corner(px(8)),
222
+ corner(px(6)),
224
223
  stroke {
225
224
  color = function()
226
225
  return theme.border(state.theme())
@@ -228,7 +227,7 @@ local function suggestions(props: Suggestions)
228
227
  },
229
228
  create "UISizeConstraint" {
230
229
  MinSize = function()
231
- return Vector2.new(px.convert(320), 0)
230
+ return Vector2.new(px.convert(213), 0)
232
231
  end,
233
232
  },
234
233
  flex():row():fill("horizontal"),
@@ -239,7 +238,7 @@ local function suggestions(props: Suggestions)
239
238
  auto = "XY",
240
239
  order = 1,
241
240
 
242
- padding { x = px(12), y = px(8) },
241
+ padding { x = px(8), y = px(5) },
243
242
  flex():column():vertical("center"):gap(8),
244
243
 
245
244
  pill {
@@ -271,8 +270,8 @@ local function suggestions(props: Suggestions)
271
270
  auto = "XY",
272
271
  order = 2,
273
272
 
274
- padding { x = px(12), y = px(8) },
275
- flex():row():gap(6),
273
+ padding { x = px(8), y = px(5) },
274
+ flex():row():gap(4),
276
275
 
277
276
  text {
278
277
  auto = "XY",
@@ -358,7 +357,7 @@ local function suggestions(props: Suggestions)
358
357
  auto = "XY",
359
358
  order = 4,
360
359
 
361
- padding(px(4)),
360
+ padding(px(3)),
362
361
  flex():row():fill("horizontal"),
363
362
 
364
363
  indexes(function()
@@ -379,7 +378,7 @@ local function suggestions(props: Suggestions)
379
378
  auto = "XY",
380
379
  order = 6,
381
380
 
382
- padding { x = px(12), y = px(6) },
381
+ padding { x = px(8), y = px(4) },
383
382
 
384
383
  text {
385
384
  auto = "XY",
@@ -2,7 +2,7 @@ local vide = require("../../vide")
2
2
 
3
3
  local create = vide.create
4
4
 
5
- return function(px: number)
5
+ return function(px: number | () -> number)
6
6
  return create "UICorner" {
7
7
  CornerRadius = function()
8
8
  return UDim.new(0, vide.read(px))
@@ -1,4 +1,5 @@
1
1
  local fade = require("../fade")
2
+ local px = require("../px")
2
3
  local state = require("../state")
3
4
  local theme = require("../theme")
4
5
  local vide = require("../../vide")
@@ -16,7 +17,7 @@ type Divider = {
16
17
  -- automatically sized parent grow to fill its own parent
17
18
  return function(props: Divider?)
18
19
  return create "Frame" {
19
- Size = UDim2.fromOffset(0, 1),
20
+ Size = px(UDim2.fromOffset(0, 1)),
20
21
  BackgroundColor3 = function()
21
22
  return theme.border(state.theme())
22
23
  end,
@@ -1,4 +1,5 @@
1
1
  local fade = require("../fade")
2
+ local px = require("../px")
2
3
  local vide = require("../../vide")
3
4
 
4
5
  local create = vide.create
@@ -14,7 +15,7 @@ return function(props: Stroke)
14
15
  return create "UIStroke" {
15
16
  ApplyStrokeMode = Enum.ApplyStrokeMode.Border,
16
17
  Color = props.color,
17
- Thickness = props.thickness or 1,
18
+ Thickness = px(props.thickness or 1),
18
19
  Transparency = fade.fade(props.transparency),
19
20
  }
20
21
  end
package/src/init.luau CHANGED
@@ -53,6 +53,7 @@ local function configure(options: types.OptionsPartial)
53
53
  set_opt(state.width, options.width)
54
54
 
55
55
  set_opt(state.max_suggestions, options.max_suggestions)
56
+ set_opt(state.clear_button, options.clear_button)
56
57
  set_opt(state.format_date, options.format_date)
57
58
  end
58
59
 
package/src/px.luau CHANGED
@@ -1,17 +1,22 @@
1
1
  local vide = require("../vide")
2
2
 
3
+ local effect = vide.effect
3
4
  local source = vide.source
4
5
  local read = vide.read
5
6
  local cleanup = vide.cleanup
6
7
 
7
8
  export type Mode = "normal" | "even" | "scale" | "floor" | "ceil"
8
9
 
9
- local BASE_RESOLUTION = Vector2.new(1920, 1080)
10
- local MIN_SCALE = 0.5
10
+ local BASE_RESOLUTION = Vector2.new(1280, 720)
11
+ const MIN_SCALE = 0.5
11
12
  local DOMINANT_AXIS = 0.5
12
13
 
13
14
  local scale = source(1)
14
15
 
16
+ local function modify_scale(scale_value: number): number
17
+ return math.max(scale_value, MIN_SCALE)
18
+ end
19
+
15
20
  local function convert(value: number, mode: Mode?): number
16
21
  return if mode == "even"
17
22
  then math.round(value * scale() * 0.5) * 2
@@ -47,18 +52,21 @@ local function px<T>(value: T | () -> T, mode: Mode? | () -> Mode?): () -> T
47
52
  end
48
53
 
49
54
  local function mount()
50
- local camera = workspace.CurrentCamera
55
+ local viewport_size = source(Vector2.new(0, 0))
51
56
 
52
- local function update()
53
- local width = math.log(camera.ViewportSize.X / BASE_RESOLUTION.X, 2)
54
- local height = math.log(camera.ViewportSize.Y / BASE_RESOLUTION.Y, 2)
55
- local centered = width + (height - width) * DOMINANT_AXIS
56
- scale(math.max(2 ^ centered, MIN_SCALE))
57
- end
57
+ effect(function()
58
+ local viewport = viewport_size()
59
+ local scaleX = math.log(viewport.X / BASE_RESOLUTION.X, 2)
60
+ local scaleY = math.log(viewport.Y / BASE_RESOLUTION.Y, 2)
61
+
62
+ scale(modify_scale(2 ^ math.lerp(scaleX, scaleY, DOMINANT_AXIS)))
63
+ end)
58
64
 
59
- update()
65
+ cleanup(workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
66
+ viewport_size(workspace.CurrentCamera.ViewportSize)
67
+ end))
60
68
 
61
- cleanup(camera:GetPropertyChangedSignal("ViewportSize"):Connect(update))
69
+ viewport_size(workspace.CurrentCamera.ViewportSize)
62
70
  end
63
71
 
64
72
  return setmetatable({ mount = mount, convert = convert, get = px_raw }, {
package/src/state.luau CHANGED
@@ -23,11 +23,12 @@ return {
23
23
  return `<b>{dateParts[1]}</b> {dateParts[2]}`
24
24
  end),
25
25
  max_suggestions = source(5),
26
+ clear_button = source(false),
26
27
 
27
- text_size = source(28),
28
- subtext_size = source(24),
28
+ text_size = source(19),
29
+ subtext_size = source(16),
29
30
 
30
- anchor = source(Vector2.zero),
31
- position = source(UDim2.new()),
32
- width = source(UDim.new(1, 0)),
31
+ anchor = source(Vector2.new(0.5, 0)),
32
+ position = source(UDim2.new(0.5, 0, 0, 0)),
33
+ width = source(UDim.new(0, 1200)),
33
34
  }
package/src/ts/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface Options {
9
9
  transparency: number;
10
10
  format_date: (log: Log) => string;
11
11
  max_suggestions: number;
12
+ clear_button: boolean;
12
13
 
13
14
  text_size: number;
14
15
  subtext_size: number;
package/src/types.luau CHANGED
@@ -14,6 +14,7 @@ export type Options = {
14
14
  transparency: number,
15
15
  format_date: (log: Log) -> string,
16
16
  max_suggestions: number,
17
+ clear_button: boolean,
17
18
 
18
19
  text_size: number,
19
20
  subtext_size: number,
@@ -32,6 +33,7 @@ export type OptionsPartial = {
32
33
  transparency: number?,
33
34
  format_date: ((log: Log) -> string)?,
34
35
  max_suggestions: number?,
36
+ clear_button: boolean?,
35
37
 
36
38
  text_size: number?,
37
39
  subtext_size: number?,