mirror of
https://github.com/vlang/v.git
synced 2025-09-16 16:02:29 +03:00
term.ui: use the new [flag]
enums (#8881)
This commit is contained in:
parent
0470baafa6
commit
260f677469
8 changed files with 92 additions and 81 deletions
|
@ -12,15 +12,15 @@ fn event(e &tui.Event, x voidptr) {
|
|||
app.tui.write('V term.input event viewer (press `esc` to exit)\n\n')
|
||||
app.tui.write('$e')
|
||||
app.tui.write('\n\nRaw event bytes: "$e.utf8.bytes().hex()" = $e.utf8.bytes()')
|
||||
if e.modifiers != 0 {
|
||||
if !e.modifiers.is_empty() {
|
||||
app.tui.write('\nModifiers: $e.modifiers = ')
|
||||
if e.modifiers & tui.ctrl != 0 {
|
||||
if e.modifiers.has(.ctrl) {
|
||||
app.tui.write('ctrl. ')
|
||||
}
|
||||
if e.modifiers & tui.shift != 0 {
|
||||
if e.modifiers.has(.shift) {
|
||||
app.tui.write('shift ')
|
||||
}
|
||||
if e.modifiers & tui.alt != 0 {
|
||||
if e.modifiers.has(.alt) {
|
||||
app.tui.write('alt. ')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,8 +174,8 @@ fn event(event &ui.Event, x voidptr) {
|
|||
y: event.y
|
||||
}
|
||||
d := event.direction == .down
|
||||
if event.modifiers & ui.ctrl != 0 {
|
||||
p := event.modifiers & ui.shift == 0
|
||||
if event.modifiers.has(.ctrl) {
|
||||
p := !event.modifiers.has(.shift)
|
||||
c := if d {
|
||||
if p { app.primary_color_idx - 1 } else { app.secondary_color_idx - 1 }
|
||||
} else {
|
||||
|
@ -212,43 +212,53 @@ fn event(event &ui.Event, x voidptr) {
|
|||
}
|
||||
app.paint(nevent)
|
||||
}
|
||||
.space {
|
||||
.space, .enter {
|
||||
oevent := *event
|
||||
nevent := ui.Event{
|
||||
...oevent
|
||||
button: ui.MouseButton.middle
|
||||
button: .left
|
||||
x: app.mouse_pos.x
|
||||
y: app.mouse_pos.y
|
||||
}
|
||||
app.paint(nevent)
|
||||
}
|
||||
.delete, .backspace {
|
||||
oevent := *event
|
||||
nevent := ui.Event{
|
||||
...oevent
|
||||
button: .middle
|
||||
x: app.mouse_pos.x
|
||||
y: app.mouse_pos.y
|
||||
}
|
||||
app.paint(nevent)
|
||||
}
|
||||
.j, .down {
|
||||
if event.modifiers & ui.shift != 0 {
|
||||
if event.modifiers.has(.shift) {
|
||||
app.set_pixel((1 + app.mouse_pos.x) / 2, app.mouse_pos.y, app.primary_color)
|
||||
}
|
||||
app.mouse_pos.y++
|
||||
}
|
||||
.k, .up {
|
||||
if event.modifiers & ui.shift != 0 {
|
||||
if event.modifiers.has(.shift) {
|
||||
app.set_pixel((1 + app.mouse_pos.x) / 2, app.mouse_pos.y, app.primary_color)
|
||||
}
|
||||
app.mouse_pos.y--
|
||||
}
|
||||
.h, .left {
|
||||
if event.modifiers & ui.shift != 0 {
|
||||
if event.modifiers.has(.shift) {
|
||||
app.set_pixel((1 + app.mouse_pos.x) / 2, app.mouse_pos.y, app.primary_color)
|
||||
}
|
||||
app.mouse_pos.x -= 2
|
||||
}
|
||||
.l, .right {
|
||||
if event.modifiers & ui.shift != 0 {
|
||||
if event.modifiers.has(.shift) {
|
||||
app.set_pixel((1 + app.mouse_pos.x) / 2, app.mouse_pos.y, app.primary_color)
|
||||
}
|
||||
app.mouse_pos.x += 2
|
||||
}
|
||||
.t {
|
||||
p := event.modifiers & ui.alt == 0
|
||||
c := if event.modifiers & ui.shift != 0 {
|
||||
p := !event.modifiers.has(.alt)
|
||||
c := if event.modifiers.has(.shift) {
|
||||
if p { app.primary_color_idx - 19 } else { app.secondary_color_idx - 19 }
|
||||
} else {
|
||||
if p { app.primary_color_idx + 19 } else { app.secondary_color_idx + 19 }
|
||||
|
@ -256,8 +266,8 @@ fn event(event &ui.Event, x voidptr) {
|
|||
app.select_color(p, c)
|
||||
}
|
||||
.r {
|
||||
p := event.modifiers & ui.alt == 0
|
||||
c := if event.modifiers & ui.shift != 0 {
|
||||
p := !event.modifiers.has(.alt)
|
||||
c := if event.modifiers.has(.shift) {
|
||||
if p { app.primary_color_idx - 1 } else { app.secondary_color_idx - 1 }
|
||||
} else {
|
||||
if p { app.primary_color_idx + 1 } else { app.secondary_color_idx + 1 }
|
||||
|
|
|
@ -515,17 +515,17 @@ fn event(e &tui.Event, x voidptr) {
|
|||
buffer.del(1)
|
||||
}
|
||||
.left {
|
||||
if e.modifiers == tui.ctrl {
|
||||
if e.modifiers == .ctrl {
|
||||
buffer.move_to_word(.left)
|
||||
} else if e.modifiers == 0 {
|
||||
} else if e.modifiers.is_empty() {
|
||||
buffer.move_cursor(1, .left)
|
||||
}
|
||||
a.magnet_x = buffer.cursor.pos_x
|
||||
}
|
||||
.right {
|
||||
if e.modifiers == tui.ctrl {
|
||||
if e.modifiers == .ctrl {
|
||||
buffer.move_to_word(.right)
|
||||
} else if e.modifiers == 0 {
|
||||
} else if e.modifiers.is_empty() {
|
||||
buffer.move_cursor(1, .right)
|
||||
}
|
||||
a.magnet_x = buffer.cursor.pos_x
|
||||
|
@ -551,16 +551,16 @@ fn event(e &tui.Event, x voidptr) {
|
|||
buffer.move_cursor(1, .end)
|
||||
}
|
||||
48...57, 97...122 { // 0-9a-zA-Z
|
||||
if e.modifiers == tui.ctrl {
|
||||
if e.modifiers == .ctrl {
|
||||
if e.code == .s {
|
||||
a.save()
|
||||
}
|
||||
} else if e.modifiers in [tui.shift, 0] && e.code != .null {
|
||||
} else if !(e.modifiers.has(.ctrl | .alt) || e.code == .null) {
|
||||
buffer.put(e.ascii.ascii_str())
|
||||
}
|
||||
}
|
||||
else {
|
||||
if e.modifiers == tui.alt {
|
||||
if e.modifiers == .alt {
|
||||
if e.code == .comma {
|
||||
a.visit_prev_file()
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue