Skip to content

Add vt100 support to windows port. #6058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ports/windows/windows_mphal.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ STATIC void assure_stdin_handle() {
}
}

#if !MICROPY_HAL_HAS_VT100
STATIC void assure_conout_handle() {
if (!con_out) {
con_out = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
Expand All @@ -52,6 +53,7 @@ STATIC void assure_conout_handle() {
assert(con_out != INVALID_HANDLE_VALUE);
}
}
#endif

void mp_hal_stdio_mode_raw(void) {
assure_stdin_handle();
Expand All @@ -60,6 +62,9 @@ void mp_hal_stdio_mode_raw(void) {
mode &= ~ENABLE_ECHO_INPUT;
mode &= ~ENABLE_LINE_INPUT;
mode &= ~ENABLE_PROCESSED_INPUT;
#if MICROPY_HAL_HAS_VT100
mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
#endif
SetConsoleMode(std_in, mode);
}

Expand Down Expand Up @@ -105,6 +110,7 @@ void mp_hal_set_interrupt_char(char c) {
}
}

#if !MICROPY_HAL_HAS_VT100
void mp_hal_move_cursor_back(uint pos) {
if (!pos) {
return;
Expand Down Expand Up @@ -184,8 +190,24 @@ STATIC int esc_seq_chr() {
}
return 0;
}
#endif

int mp_hal_stdin_rx_chr(void) {
#if MICROPY_HAL_HAS_VT100
assure_stdin_handle();
BOOL read_ok;
DWORD num_read;
char inchar;
LPVOID buf = &inchar;
for (;;) {
read_ok = ReadFile(std_in, buf, 1, &num_read, NULL);
if (!read_ok || !num_read) {
continue;
} else {
return inchar;
}
}
#else
// currently processing escape seq?
const int ret = esc_seq_chr();
if (ret) {
Expand Down Expand Up @@ -218,6 +240,7 @@ int mp_hal_stdin_rx_chr(void) {
return c;
}
}
#endif
}

void mp_hal_stdout_tx_strn(const char *str, size_t len) {
Expand Down
2 changes: 2 additions & 0 deletions ports/windows/windows_mphal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

#define MICROPY_HAL_HAS_VT100 (0)

#if !MICROPY_HAL_HAS_VT100
void mp_hal_move_cursor_back(unsigned int pos);
void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase);
#endif

#undef mp_hal_ticks_cpu
mp_uint_t mp_hal_ticks_cpu(void);
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy