Comments (6)
Here's an attempt: b5480c6
It assumes that it's UTF-16 on Windows, this works on Windows 10 for me atleast.
Similarly it assumes UTF-8 on Linux which has also worked in my limited testing. For future work it would probably make sense to detect the locale and not try and parse non-utf8 data as utf-8, I need to see if I can setup an environment where I can test this easily.
from pancurses.
What kind of behaviour are you looking for exactly? I fixed the panicing on unexpected values, pancurses should now return larger input values as Input::Unknown's as it should in commit 8f2b779
from pancurses.
I don't know which behaviour should be favored, but all platforms should behave uniform.
On linux, pancurses doesn't parse anything, and directly returns the raw utf8 bytes one by one.
On Windows on the other hand it will return the char directly as one char instead of two separate ones.
I hope I could make clear what my concern is. I can test the code tomorrow.
from pancurses.
It's not so much that pancurses changes things, the logic is actually the same on both platforms. If the output differs it's because there's a difference between PDCurses and ncurses. It would be good for pancurses to correctly parse characters though.
from pancurses.
On linux, ncurses
returns individual bytes. The actual encoding depends on the terminal configuration, but it's often utf8.
I don't have a windows machine to test, but I assume pdcurses returns utf16 values (is it configurable? see https://github.com/wmcbrine/PDCurses/blob/cdddccd6bbab39316a8c9e32948c3ad5d5bbb091/wincon/README.md).
Returning input_byte as u8 as char
is a bit weird:
- For codepoints values under 128 (ASCII), in both utf8 and utf16, the input value equals the unicode number, so this conversion works.
- For codepoints between 128 and 255, utf8 will produce two bytes, and each will be wrongly treated as a
char
. UTF16 still coincides with codepoints, so on windows these values are still properly parsed. - For codepoints above 255, the value will no longer fit in a
u8
, so it will be returned as "unknown" on windows. On linux, it will still return multiple weird characters. - And that's not even considering different locales/terminal configurations.
I see two possibilities:
- Not parse anything, but be honest about it, and return either a
u8
on linux or au16
on windows. Problem: this means the datatype itself changes between platforms (we could return au16
in both cases but it's not as clean). - Parse the input correctly for each platform. This is a bit tricky, as it means:
- On windows, parse as utf-16 (is it even actually utf-16?)
- On linux, parse the bytes depending on the terminal configuration. Should this depend on the locale? Or should we assume it's utf8?
from pancurses.
Closing this with the release of v0.15 which includes the improvements to input handling. I didn't add support for anything other than UTF-8 on Linux, that's left for some time in the future.
from pancurses.
Related Issues (20)
- `ctrl`+`space` causes panic on `unwrap` HOT 1
- *mut i8 cannot be sent between threads safely HOT 1
- Segfault can be triggered with printw HOT 2
- _
- error: linking with `link.exe` failed: exit code: 1120 (x86_64-pc-windows-msvc) HOT 3
- Moving subwindow leaves behind the old windows HOT 3
- win32a consistently crashes HOT 1
- mvprintw and printw should not be exposed HOT 1
- Enter key yields Input::Character('\n'), not Input::KeyEnter HOT 2
- Release and activity HOT 1
- Disable wrapping
- Window::border() and unicode HOT 3
- panic of unwrap() on CString creation
- Get and set XY position of cursor (not mouse) HOT 1
- Can a combination of keypresses detected by ncurses be detected in pancurses?
- Example Code throws Error
- non-blokcing getch ? HOT 3
- Input enum for control/shift?
- noecho before initscr
- Update to ncurses 6.0.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pancurses.