Skip to content

Instantly share code, notes, and snippets.

@spytheman
Created January 26, 2020 17:43
Show Gist options
  • Save spytheman/a9028cf856b6696376663a448e964e7a to your computer and use it in GitHub Desktop.
Save spytheman/a9028cf856b6696376663a448e964e7a to your computer and use it in GitHub Desktop.
import os
fn C.scanf()
fn get_cursor_position() (int,int) {
mut x := 0 mut y := 0
C.printf('\033[6n')
C.scanf('\033[%d;%dR', &x, &y)
return x,y
}
fn main(){
print('hello world!')
oldmode := os.exec('stty -g') or { panic(err) }
os.exec('stty raw -echo min 1') or { panic(err) }
x,y := get_cursor_position()
os.system('stty $oldmode.output')
eprintln('\nx: $x | y: $y | oldmode: $oldmode.output')
}
@spytheman
Copy link
Author

0[19:45:26] /v/vui LINUX $ /v/nv/v run x.v
hello world!
x: 19 | y: 13 | oldmode: 5500:5:bf:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
0[19:45:28] /v/vui LINUX $

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment