diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/term/ui/input_nix.c.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/vlib/term/ui/input_nix.c.v')
-rw-r--r-- | v_windows/v/vlib/term/ui/input_nix.c.v | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/v_windows/v/vlib/term/ui/input_nix.c.v b/v_windows/v/vlib/term/ui/input_nix.c.v new file mode 100644 index 0000000..e806fb8 --- /dev/null +++ b/v_windows/v/vlib/term/ui/input_nix.c.v @@ -0,0 +1,70 @@ +// Copyright (c) 2020-2021 Raúl Hernández. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. +module ui + +struct ExtraContext { +mut: + read_buf []byte +} + +const ( + ctx_ptr = &Context(0) +) + +pub fn init(cfg Config) &Context { + mut ctx := &Context{ + cfg: cfg + } + ctx.read_buf = []byte{cap: cfg.buffer_size} + + // lmao + unsafe { + x := &ui.ctx_ptr + *x = ctx + _ = x + } + return ctx +} + +[inline] +fn save_title() { + // restore the previously saved terminal title + print('\x1b[22;0t') +} + +[inline] +fn load_title() { + // restore the previously saved terminal title + print('\x1b[23;0t') +} + +pub fn (mut ctx Context) run() ? { + if ctx.cfg.use_x11 { + ctx.fail('error: x11 backend not implemented yet') + exit(1) + } else { + ctx.termios_setup() ? + ctx.termios_loop() + } +} + +// shifts the array left, to remove any data that was just read, and updates its len +// TODO: remove +[inline] +fn (mut ctx Context) shift(len int) { + unsafe { + C.memmove(ctx.read_buf.data, &byte(ctx.read_buf.data) + len, ctx.read_buf.cap - len) + ctx.resize_arr(ctx.read_buf.len - len) + } +} + +// TODO: don't actually do this, lmao +[inline] +fn (mut ctx Context) resize_arr(size int) { + mut l := unsafe { &ctx.read_buf.len } + unsafe { + *l = size + _ = l + } +} |