Repository: ilai-deutel/kibi (language: rust)

Issue:
Windows 10 powershell or cmd Could not obtain cursor position
Since update #9 and #26 were resolved, I wanted to test with the lastest version.

I did `cargo install --git https://github.com/ilai-deutel/kibi.git`

Doing the command `kibi` in both _cmd_ or _powershell_ results in the same error.
It freezes on this.
```
D:\>kibi
[999C[999B[6n
```

Then doing Ctrl+C 
```
D:\>kibi
[999C[999B[6n[2J[HError: Could not obtain cursor position
```



Discussion / hints:
Thank you for reporting this issue.

* What is the output of `systeminfo | findstr /B /C:"OS Name" /C:"OS Version"`?
* I have pushed a few changes to master, can you reinstall kibi and let me know if you still get the same error?
Here is the output :
```
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.18362 N/A Build 18362
```

I now have another error, with the current version.
```
D:\> kibi                                                                                                                                                                                             [?25l[H[K[38;5;240m1 │[m[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m                                                                                                                 Kibi - version 0.1.2                                                                                                 
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[K[38;5;240m~ │[m
[7m[No Name]                                                                                                                                                                                                                                       | 0B | 1:1[m
[KCtrl-S = save | Ctrl-Q = quit | Ctrl-F = find | Ctrl-G = go to | Ctrl-D = duplicate[1;4H[?25h[?25l[H[K[38;5;240m1 │[m[7mV[m[m
```
Hoping this is helpful. 
Let me know if I can test other things.

Fix patch:
diff --git a/README.md b/README.md
index 80da5551..0863e076 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,17 @@
 A configurable text editor with UTF-8 support, incremental search, syntax highlighting, line numbers and more, written
 in less than 1024 lines<sup>[1](#counted-with)</sup> of Rust with minimal dependencies.
 
-Kibi is compatible with Linux, macOS, and Windows 10 (beta).
+Kibi is compatible with Linux, macOS, and Windows 10<sup>[2](#windows-version)</sup> (beta).
 
 This project is inspired by [`kilo`](https://github.com/antirez/kilo), a text editor written in C.
 See [comparison](#comparison-with-kilo) below for a list of additional features.
 
 Contributions are welcome! Be careful to stay below the 1024-line limit...
 
-<sub><a name="counted-with">1.</a>: Counted with [`tokei`](https://github.com/XAMPPRocky/tokei)</sub>
+<sub><a name="counted-with">1.</a>: Counted with [`tokei`](https://github.com/XAMPPRocky/tokei)</sub> \
+<sub><a name="windows-version">2.</a>: Kibi requires the terminal to support ANSI escape sequences. Windows 10 version
+1703 ([Creators Update](https://devblogs.microsoft.com/commandline/windows-10-creators-update-whats-new-in-bashwsl-windows-console),
+April 2017) and above are supported.</sub>
 
 ## Installation
 
diff --git a/src/windows.rs b/src/windows.rs
index f1ad725a..ba4ccd13 100644
--- a/src/windows.rs
+++ b/src/windows.rs
@@ -5,27 +5,29 @@
 use std::{io, sync::mpsc::Receiver};
 
 use winapi::um::wincon::*;
-use winapi_util::{console, HandleRef};
+use winapi_util::{console as cons, HandleRef};
 
 use crate::Error;
 
-// On Windows systems, the terminal mode is represented as an unsigned int.
-pub(crate) type TermMode = u32;
+// On Windows systems, the terminal mode is represented as 2 unsigned integers (one for stdin, one
+// for stdout).
+pub(crate) type TermMode = (u32, u32);
 
 /// Return configuration directories for Windows systems
 pub(crate) fn conf_dirs() -> [Option<String>; 1] { [std::env::var("APPDATA").ok()] }
 
 /// Return the current window size as (rows, columns).
 pub(crate) fn get_window_size() -> Result<(usize, usize), Error> {
-    let w_rect = console::screen_buffer_info(HandleRef::stdout())?.window_rect();
+    let w_rect = cons::screen_buffer_info(HandleRef::stdout())?.window_rect();
     Ok(((w_rect.bottom - w_rect.top + 1) as usize, (w_rect.right - w_rect.left + 1) as usize))
 }
 
 pub(crate) fn get_window_size_update_receiver() -> Result<Option<Receiver<()>>, Error> { Ok(None) }
 
 /// Set the terminal mode.
-pub(crate) fn set_term_mode(stdin_term_mode: &TermMode) -> Result<(), io::Error> {
-    console::set_mode(HandleRef::stdin(), *stdin_term_mode)
+pub(crate) fn set_term_mode((stdin_mode, stdout_mode): &TermMode) -> Result<(), io::Error> {
+    cons::set_mode(HandleRef::stdin(), *stdin_mode)?;
+    cons::set_mode(HandleRef::stdout(), *stdout_mode)
 }
 
 /// Enable raw mode, and return the original terminal mode.
@@ -33,9 +35,15 @@ pub(crate) fn set_term_mode(stdin_term_mode: &TermMode) -> Result<(), io::Error>
 /// Documentation for console modes is available at:
 /// <https://docs.microsoft.com/en-us/windows/console/setconsolemode>
 pub(crate) fn enable_raw_mode() -> Result<TermMode, Error> {
-    let orig_mode_in = console::mode(HandleRef::stdin())?;
-    let mode_in = (orig_mode_in | ENABLE_VIRTUAL_TERMINAL_INPUT)
+    // (mode_in0, mode_out0) are the original terminal modes
+    let (mode_in0, mode_out0) = (cons::mode(HandleRef::stdin())?, cons::mode(HandleRef::stdout())?);
+
+    // (mode_in, mode_out) are the new terminal modes
+    let mode_in = (mode_in0 | ENABLE_VIRTUAL_TERMINAL_INPUT)
         & !(ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
-    set_term_mode(&mode_in)?;
-    Ok(orig_mode_in)
+    let mode_out = (mode_out0 | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
+        | (DISABLE_NEWLINE_AUTO_RETURN | ENABLE_PROCESSED_OUTPUT);
+
+    set_term_mode(&(mode_in, mode_out))?;
+    Ok((mode_in0, mode_out0))
 }


Test patch: