From 77a487fe4f2ce2ad619d062df827268071ec1859 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 22:42:03 +0000 Subject: [PATCH] Add ASCII Setup to the Windows app The HyperTerminal ASCII Setup dialog (Modem menu), kept in [ascii]: - Sending: Enter as CR LF, local echo, line and character delays. - Receiving: an LF after each CR, 7-bit ASCII, wrap of long lines. The receive items are in the core terminal (dmc_vt_set_ascii), with tests. The settings apply to the modem and Remote terminals. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRRekyRUhR43KbmGNXK --- README.md | 1 + core/include/dmodemctl.h | 8 +++ core/src/vt.c | 44 ++++++++++-- core/src/vtint.h | 2 + core/test/dmodemctl_test.c | 39 +++++++++++ docs/design.md | 15 +++++ windows/res/app.rc | 24 +++++++ windows/sources.cmake | 3 +- windows/src/app.h | 18 +++++ windows/src/ascii.cpp | 133 +++++++++++++++++++++++++++++++++++++ windows/src/main.cpp | 3 + windows/src/remote.cpp | 1 + windows/src/resource.h | 11 +++ windows/src/term.cpp | 1 + windows/src/termview.cpp | 21 ++++++ windows/src/xfer.cpp | 14 ++-- 16 files changed, 321 insertions(+), 17 deletions(-) create mode 100644 windows/src/ascii.cpp diff --git a/README.md b/README.md index b0d87e2..099eb24 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ libdmodemctl. Thus they operate in the same way. LGPL-2.0-or-later: `core/licenses/syncterm-fonts-LGPL-2.0.txt`) - **File transfers** (Windows app): send and receive files on the modem line or on a Telnet, rlogin or SSH login. The protocols are the same as the D-Modem app: ZMODEM (with Automatic Receive when the remote side starts sz, rz or kermit -s, and with Crash Recovery), YMODEM, YMODEM-G, XMODEM, XMODEM-1K, Kermit, Intel HEX, Motorola S-records and plain text. Use the Transfer menu, or the Send and Receive buttons of the Terminal page - **Copy and capture** (Windows app): select text with the mouse (Shift and the mouse when the remote side uses the mouse), then copy it. Paste to Host, Select All, Capture Text (to a file), Capture to Printer, and Print (the screen or the selection). Text that the remote side sends to its printer port goes to the printer. Use the Edit and Transfer menus, or click the right mouse button on the terminal +- **ASCII Setup** (Windows app, Modem menu): the same items as HyperTerminal. For the data that you send: Enter sends CR LF, the local echo, and the line delay and character delay of a text file. For the data that you receive: an LF after each CR, 7-bit ASCII, and the wrap of long lines. The settings apply to the modem terminal and to the Remote terminal - **Settings**: each modem setting as a native control, from AT!M - **Call Stats**: the rate, modulation, error control and line figures of the last call (AT#UD, ATI11) - **Line settings**: a SIP account, a USB modem, or a modem that already runs (dmodemd, or a hardware modem such as the MultiTech MT9234MU) diff --git a/core/include/dmodemctl.h b/core/include/dmodemctl.h index d4e8e9d..9abc86f 100644 --- a/core/include/dmodemctl.h +++ b/core/include/dmodemctl.h @@ -543,6 +543,14 @@ DMC_API int dmc_vt_char_bytes(dmc_vt *t, uint32_t cp, int mods, char *buf, /* what Enter sends (0 CR, 1 CR LF, 2 LF) and Backspace (0x08 or 0x7f) */ DMC_API void dmc_vt_set_enter(dmc_vt *t, int mode); DMC_API void dmc_vt_set_backspace(dmc_vt *t, int code); +/* HyperTerminal's ASCII Setup, for the received data: an LF added after + each CR (the LF of a CR LF is not doubled), each byte set to 7 bits, + and no wrap at the right margin (the last column is written again) */ +#define DMC_VT_ASCII_ADD_LF 1 +#define DMC_VT_ASCII_7BIT 2 +#define DMC_VT_ASCII_NO_WRAP 4 +DMC_API void dmc_vt_set_ascii(dmc_vt *t, int flags); +DMC_API int dmc_vt_get_ascii(const dmc_vt *t); /* a mouse event, when the remote asked for them: button 0-2, 64 and 65 the wheel; the bytes to send (0: none) */ DMC_API int dmc_vt_mouse_wanted(const dmc_vt *t); diff --git a/core/src/vt.c b/core/src/vt.c index 2bb895a..9dc71e4 100644 --- a/core/src/vt.c +++ b/core/src/vt.c @@ -713,7 +713,7 @@ void vt_print(dmc_vt *t, int32_t cp) } t->last_char = cp; if (t->pending_wrap) { - if (t->autowrap) { + if (t->autowrap && !(t->ascii & DMC_VT_ASCII_NO_WRAP)) { t->screen[t->cy]->wrapped = 1; vt_carriage_return(t); vt_index(t); @@ -726,7 +726,7 @@ void vt_print(dmc_vt *t, int32_t cp) if (t->cx >= lc) t->cx = lc - 1; if (w == 2 && t->cx == lc - 1) { - if (!t->autowrap || lc < 2) + if (!t->autowrap || (t->ascii & DMC_VT_ASCII_NO_WRAP) || lc < 2) return; line_clear(t->screen[t->cy], t->cx, t->cols, t->style); t->screen[t->cy]->wrapped = 1; @@ -1567,21 +1567,53 @@ void dmc_vt_resize(dmc_vt *t, int cols, int rows) int dmc_vt_cols(const dmc_vt *t) { return t->cols; } int dmc_vt_rows(const dmc_vt *t) { return t->rows; } +/* one byte from the remote, to the terminal of the profile */ +static void feed_byte(dmc_vt *t, int b) +{ + if (t->interp->reads_octets) + t->interp->ops->process(t->interp, b); + else + decode(t, b); +} + void dmc_vt_feed(dmc_vt *t, const char *data, int n) { int i; for (i = 0; i < n; i++) { int b = (unsigned char)data[i]; - if (t->interp->reads_octets) - t->interp->ops->process(t->interp, b); - else - decode(t, b); + if (t->ascii & DMC_VT_ASCII_7BIT) + b &= 0x7f; + if (t->ascii & DMC_VT_ASCII_ADD_LF) { + /* a CR gets its LF; the LF of a CR LF is not + given two times */ + if (b == '\n' && t->ascii_cr) { + t->ascii_cr = 0; + continue; + } + t->ascii_cr = b == '\r'; + feed_byte(t, b); + if (b == '\r') + feed_byte(t, '\n'); + continue; + } + feed_byte(t, b); } if (t->interp->ops->flush) t->interp->ops->flush(t->interp); t->changed = 1; } +void dmc_vt_set_ascii(dmc_vt *t, int flags) +{ + t->ascii = flags; + t->ascii_cr = 0; +} + +int dmc_vt_get_ascii(const dmc_vt *t) +{ + return t->ascii; +} + int dmc_vt_reply(dmc_vt *t, char *buf, int max) { return buf_take(&t->reply, buf, max); diff --git a/core/src/vtint.h b/core/src/vtint.h index 581c376..07e1fb3 100644 --- a/core/src/vtint.h +++ b/core/src/vtint.h @@ -272,6 +272,8 @@ struct dmc_vt { struct vt_link *link; int join_next; int autowrap, origin_mode, insert_mode, newline_mode; + /* ASCII Setup's receive items (DMC_VT_ASCII_*), and a CR just fed */ + int ascii, ascii_cr; int top, bottom; uint8_t *tabs; int lr_margins, left, right; diff --git a/core/test/dmodemctl_test.c b/core/test/dmodemctl_test.c index 0001080..e2d0afa 100644 --- a/core/test/dmodemctl_test.c +++ b/core/test/dmodemctl_test.c @@ -1257,6 +1257,44 @@ static void test_path(void) dmc_path_free(p); } +/* ASCII Setup's receive items: an LF after a CR, 7 bits, no wrap */ +static void test_vt_ascii(void) +{ + dmc_vt *t = dmc_vt_new(10, 5, 100); + const char *s; + dmc_vt_set_ascii(t, DMC_VT_ASCII_ADD_LF); + CHECK(dmc_vt_get_ascii(t) == DMC_VT_ASCII_ADD_LF); + /* a CR alone gets its LF; a CR LF (its LF in the next chunk too) + gets no second one */ + s = "one\rtwo\r"; + dmc_vt_feed(t, s, (int)strlen(s)); + s = "\nthree"; + dmc_vt_feed(t, s, (int)strlen(s)); + CHECK_STR(dmc_vt_text(t, 0), "one"); + CHECK_STR(dmc_vt_text(t, 1), "two"); + CHECK_STR(dmc_vt_text(t, 2), "three"); + CHECK(dmc_vt_cursor_row(t) == 2); + /* 7 bits: 0xC1 is 'A' */ + dmc_vt_reset(t); + dmc_vt_set_ascii(t, DMC_VT_ASCII_7BIT); + s = "\xc1\xe2"; + dmc_vt_feed(t, s, (int)strlen(s)); + CHECK_STR(dmc_vt_text(t, 0), "Ab"); + /* no wrap: the last column written again */ + dmc_vt_reset(t); + dmc_vt_set_ascii(t, DMC_VT_ASCII_NO_WRAP); + s = "0123456789XY"; + dmc_vt_feed(t, s, (int)strlen(s)); + CHECK_STR(dmc_vt_text(t, 0), "012345678Y"); + CHECK_STR(dmc_vt_text(t, 1), ""); + /* and with wrap, as before */ + dmc_vt_reset(t); + dmc_vt_set_ascii(t, 0); + dmc_vt_feed(t, s, (int)strlen(s)); + CHECK_STR(dmc_vt_text(t, 1), "XY"); + dmc_vt_free(t); +} + int main(int argc, char **argv) { const char *dir = argc > 1 ? argv[1] : "."; @@ -1271,6 +1309,7 @@ int main(int argc, char **argv) test_vt(); test_vt_profiles(); test_vt_noise(); + test_vt_ascii(); test_daemon(); test_voice(); test_voicemail(); diff --git a/docs/design.md b/docs/design.md index 9fd4f8b..de8e053 100644 --- a/docs/design.md +++ b/docs/design.md @@ -134,6 +134,21 @@ text into the scrollback. The clipboard gets Unicode text and the text of the ANSI code page. - Paste to Host (Shift+Insert) types the clipboard text. +`ascii.cpp` has the ASCII Setup dialog (Modem menu). `dmodem.ini` keeps +the settings in the `[ascii]` section: `send_lf`, `echo`, `line_delay`, +`char_delay`, `add_lf`, `seven_bit` and `wrap`. The app applies them to +the two terminals: + +- `send_lf` sets Enter to CR LF (`dmc_vt_set_enter`). +- `echo` shows the characters that you type on the terminal. The app does + not show the escape sequences of the keys (for example, the arrow keys). +- `add_lf`, `seven_bit` and `wrap` go to `dmc_vt_set_ascii`. With + `DMC_VT_ASCII_ADD_LF`, the terminal adds an LF after each CR that it + receives. When an LF follows the CR, the terminal does not use that LF, + thus a CR LF does not give two lines. `DMC_VT_ASCII_7BIT` removes bit 8 + of each byte. `DMC_VT_ASCII_NO_WRAP` stops the wrap at the right margin: + the terminal writes each new character in the last column. + `capture.cpp` has the captures. Each capture is of one line (the modem or the Remote login). The capture does not get the bytes of a file transfer. diff --git a/windows/res/app.rc b/windows/res/app.rc index 9da08aa..c641936 100644 --- a/windows/res/app.rc +++ b/windows/res/app.rc @@ -19,6 +19,7 @@ BEGIN BEGIN MENUITEM "&Start or Stop", IDM_START MENUITEM "&Line Settings...", IDM_LINE + MENUITEM "&ASCII Setup...", IDM_ASCII MENUITEM SEPARATOR MENUITEM "&Print...", IDM_FPRINT MENUITEM SEPARATOR @@ -191,6 +192,29 @@ BEGIN PUSHBUTTON "Cancel", IDCANCEL, 222, 130, 50, 14 END +/* the Modem menu's ASCII Setup, as HyperTerminal has it */ +IDD_ASCII DIALOG 0, 0, 220, 176 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "ASCII Setup" +FONT 8, "MS Shell Dlg" +BEGIN + GROUPBOX "ASCII Sending", -1, 8, 6, 204, 74 + AUTOCHECKBOX "&Send line ends with line feeds", IDC_A_SENDLF, 16, 18, 188, 10 + AUTOCHECKBOX "&Echo typed characters locally", IDC_A_ECHO, 16, 32, 188, 10 + LTEXT "&Line delay:", -1, 16, 48, 70, 8 + EDITTEXT IDC_A_LINEDELAY, 90, 46, 36, 12, ES_NUMBER + LTEXT "milliseconds.", -1, 130, 48, 70, 8 + LTEXT "&Character delay:", -1, 16, 64, 70, 8 + EDITTEXT IDC_A_CHARDELAY, 90, 62, 36, 12, ES_NUMBER + LTEXT "milliseconds.", -1, 130, 64, 70, 8 + GROUPBOX "ASCII Receiving", -1, 8, 86, 204, 62 + AUTOCHECKBOX "&Append line feeds to incoming line ends", IDC_A_ADDLF, 16, 98, 188, 10 + AUTOCHECKBOX "&Force incoming data to 7-bit ASCII", IDC_A_7BIT, 16, 112, 188, 10 + AUTOCHECKBOX "&Wrap lines that exceed terminal width", IDC_A_WRAP, 16, 126, 188, 10 + DEFPUSHBUTTON "OK", IDOK, 104, 156, 50, 14 + PUSHBUTTON "Cancel", IDCANCEL, 162, 156, 50, 14 +END + /* a transfer as it goes (modeless) */ IDD_XFER DIALOG 0, 0, 260, 146 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE diff --git a/windows/sources.cmake b/windows/sources.cmake index 8d4fc31..fa1b763 100644 --- a/windows/sources.cmake +++ b/windows/sources.cmake @@ -13,5 +13,6 @@ set(DMODEM_WIN_SOURCES termview.cpp remote.cpp xfer.cpp - capture.cpp) + capture.cpp + ascii.cpp) list(TRANSFORM DMODEM_WIN_SOURCES PREPEND "${CMAKE_CURRENT_LIST_DIR}/src/") diff --git a/windows/src/app.h b/windows/src/app.h index 724e4b0..1c705ae 100644 --- a/windows/src/app.h +++ b/windows/src/app.h @@ -183,6 +183,9 @@ void termview_reset(HWND w); void termview_size(HWND w, int *cols, int *rows); /* what Backspace sends (DEL unless set) */ void termview_set_backspace(HWND w, char b); +/* ASCII Setup: the received data's DMC_VT_ASCII_* flags, what Enter sends + (0 CR, 1 CR LF), and the local echo */ +void termview_set_ascii(HWND w, int flags, int enter, bool echo); /* the selection (drag with the left button, double-click a word): to the clipboard; the clipboard's text typed; all the lines selected */ bool termview_has_selection(HWND w); @@ -230,6 +233,21 @@ void xfer_set_auto(bool on); /* the transfer's dialog's keys (IsDialogMessage) */ bool xfer_dialog_key(MSG *m); +/* ascii.cpp: ASCII Setup ([ascii] in dmodem.ini), for both terminals */ +struct AsciiSetup { + bool send_lf; /* Enter sends CR LF */ + bool echo; /* what is typed shown here too */ + int line_delay; /* a text file sent: ms after each line */ + int char_delay; /* and after each character */ + bool add_lf; /* an LF added after each CR received */ + bool seven_bit; /* the data received as 7-bit ASCII */ + bool wrap; /* lines wrap at the right margin */ +}; +void ascii_load(AsciiSetup *a); +/* the settings to a terminal control */ +void ascii_apply(HWND view); +void ascii_dialog(HWND parent); + /* capture.cpp: Capture Text, Capture to Printer and Print, for a line */ enum { CAPTURE_OFF, CAPTURE_ON, CAPTURE_PAUSED }; /* what came on the line for its terminal (not a transfer's bytes) */ diff --git a/windows/src/ascii.cpp b/windows/src/ascii.cpp new file mode 100644 index 0000000..e02d061 --- /dev/null +++ b/windows/src/ascii.cpp @@ -0,0 +1,133 @@ +/* + * SPDX-License-Identifier: AGPL-3.0-only + * Copyright (C) 2026 D-Modem Authors + * + * ascii.cpp - ASCII Setup, as HyperTerminal has it, kept in dmodem.ini + * ([ascii]): for the data sent, Enter as CR LF, the local + * echo, and the line and character delays of a text file + * sent (xfer.cpp); for the data received, an LF after each + * CR, 7-bit ASCII, and the wrap at the right margin. The + * settings apply to the two terminals (the modem's and the + * Remote page's). + */ +#include +#include + +#include "app.h" +#include "resource.h" + +static void ini(char *out, int n) +{ + char dir[MAX_PATH]; + app_data_dir(dir, sizeof(dir)); + _snprintf(out, n, "%s\\dmodem.ini", dir); + out[n - 1] = '\0'; +} + +static int get(const char *key, int def) +{ + char path[MAX_PATH]; + ini(path, sizeof(path)); + return (int)GetPrivateProfileInt("ascii", key, def, path); +} + +static void put(const char *key, int v) +{ + char path[MAX_PATH], s[16]; + ini(path, sizeof(path)); + _snprintf(s, sizeof(s), "%d", v); + s[sizeof(s) - 1] = '\0'; + WritePrivateProfileString("ascii", key, s, path); +} + +void ascii_load(AsciiSetup *a) +{ + a->send_lf = get("send_lf", 0) != 0; + a->echo = get("echo", 0) != 0; + a->line_delay = get("line_delay", 0); + a->char_delay = get("char_delay", 0); + a->add_lf = get("add_lf", 0) != 0; + a->seven_bit = get("seven_bit", 0) != 0; + a->wrap = get("wrap", 1) != 0; +} + +static void save(const AsciiSetup *a) +{ + put("send_lf", a->send_lf); + put("echo", a->echo); + put("line_delay", a->line_delay); + put("char_delay", a->char_delay); + put("add_lf", a->add_lf); + put("seven_bit", a->seven_bit); + put("wrap", a->wrap); +} + +void ascii_apply(HWND view) +{ + if (!view) + return; + AsciiSetup a; + ascii_load(&a); + int flags = (a.add_lf ? DMC_VT_ASCII_ADD_LF : 0) | + (a.seven_bit ? DMC_VT_ASCII_7BIT : 0) | + (a.wrap ? 0 : DMC_VT_ASCII_NO_WRAP); + termview_set_ascii(view, flags, a.send_lf ? 1 : 0, a.echo); +} + +/* a delay box: 0 to 9999 ms */ +static int delay_of(HWND d, int id) +{ + BOOL ok; + UINT v = GetDlgItemInt(d, id, &ok, FALSE); + if (!ok) + return 0; + return v > 9999 ? 9999 : (int)v; +} + +static INT_PTR CALLBACK ascii_proc(HWND d, UINT m, WPARAM wp, LPARAM lp) +{ + AsciiSetup *a = (AsciiSetup *)GetWindowLongPtr(d, DWLP_USER); + switch (m) { + case WM_INITDIALOG: + a = (AsciiSetup *)lp; + SetWindowLongPtr(d, DWLP_USER, (LONG_PTR)a); + CheckDlgButton(d, IDC_A_SENDLF, a->send_lf ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(d, IDC_A_ECHO, a->echo ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemInt(d, IDC_A_LINEDELAY, (UINT)a->line_delay, FALSE); + SetDlgItemInt(d, IDC_A_CHARDELAY, (UINT)a->char_delay, FALSE); + CheckDlgButton(d, IDC_A_ADDLF, a->add_lf ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(d, IDC_A_7BIT, a->seven_bit ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(d, IDC_A_WRAP, a->wrap ? BST_CHECKED : BST_UNCHECKED); + return TRUE; + case WM_COMMAND: + switch (LOWORD(wp)) { + case IDOK: + a->send_lf = IsDlgButtonChecked(d, IDC_A_SENDLF) == BST_CHECKED; + a->echo = IsDlgButtonChecked(d, IDC_A_ECHO) == BST_CHECKED; + a->line_delay = delay_of(d, IDC_A_LINEDELAY); + a->char_delay = delay_of(d, IDC_A_CHARDELAY); + a->add_lf = IsDlgButtonChecked(d, IDC_A_ADDLF) == BST_CHECKED; + a->seven_bit = IsDlgButtonChecked(d, IDC_A_7BIT) == BST_CHECKED; + a->wrap = IsDlgButtonChecked(d, IDC_A_WRAP) == BST_CHECKED; + EndDialog(d, IDOK); + return TRUE; + case IDCANCEL: + EndDialog(d, IDCANCEL); + return TRUE; + } + break; + } + return FALSE; +} + +void ascii_dialog(HWND parent) +{ + AsciiSetup a; + ascii_load(&a); + if (DialogBoxParam(app.inst, MAKEINTRESOURCE(IDD_ASCII), parent, + ascii_proc, (LPARAM)&a) != IDOK) + return; + save(&a); + ascii_apply(*term_line.view); + ascii_apply(*remote_line.view); +} diff --git a/windows/src/main.cpp b/windows/src/main.cpp index 9175813..8450d8d 100644 --- a/windows/src/main.cpp +++ b/windows/src/main.cpp @@ -314,6 +314,9 @@ static LRESULT CALLBACK main_proc(HWND w, UINT m, WPARAM wp, LPARAM lp) app_state(); } return 0; + case IDM_ASCII: + ascii_dialog(w); + return 0; case IDM_START: if (link_running()) link_stop(); diff --git a/windows/src/remote.cpp b/windows/src/remote.cpp index 62e068a..d2d92c8 100644 --- a/windows/src/remote.cpp +++ b/windows/src/remote.cpp @@ -1403,6 +1403,7 @@ HWND remote_page_new(HWND parent) #endif view = termview_new(page, IDC_R_TERM, typed, NULL); termview_set_printer(view, capture_printed, &remote_line); + ascii_apply(view); status_txt = make_child("STATIC", "Not connected", SS_LEFTNOWORDWRAP, page, IDC_R_STATUS); make_child("STATIC", "&Terminal:", SS_RIGHT, page, IDC_R_TYPELABEL); diff --git a/windows/src/resource.h b/windows/src/resource.h index 4cf2d10..0478d87 100644 --- a/windows/src/resource.h +++ b/windows/src/resource.h @@ -27,6 +27,7 @@ #define IDM_CAPSTOP 214 #define IDM_CAPPRINT 215 #define IDM_PRNPAUSE 216 +#define IDM_ASCII 217 #define IDC_STATUS 300 #define IDC_TABS 301 @@ -191,4 +192,14 @@ #define IDC_X_RESULT 1233 #define IDC_X_SKIP 1234 +/* ASCII Setup */ +#define IDD_ASCII 1240 +#define IDC_A_SENDLF 1241 +#define IDC_A_ECHO 1242 +#define IDC_A_LINEDELAY 1243 +#define IDC_A_CHARDELAY 1244 +#define IDC_A_ADDLF 1245 +#define IDC_A_7BIT 1246 +#define IDC_A_WRAP 1247 + #endif diff --git a/windows/src/term.cpp b/windows/src/term.cpp index 4959d5a..4fb7c18 100644 --- a/windows/src/term.cpp +++ b/windows/src/term.cpp @@ -126,6 +126,7 @@ HWND term_page_new(HWND parent) termview_set_printer(term, capture_printed, &term_line); /* the modem's configurator wants Backspace as BS */ termview_set_backspace(term, 0x08); + ascii_apply(term); char path[MAX_PATH], v[64]; ini(path, sizeof(path)); GetPrivateProfileString("terminal", "type", "xterm", v, sizeof(v), path); diff --git a/windows/src/termview.cpp b/windows/src/termview.cpp index c1c611e..63df435 100644 --- a/windows/src/termview.cpp +++ b/windows/src/termview.cpp @@ -52,6 +52,7 @@ struct TermView { int ar, ac, er, ec; TermPrintedFn pfn; /* what the remote prints goes to it */ void *pctx; + bool echo; /* ASCII Setup: what is typed also shown */ HFONT fonts[4]; /* regular, bold, italic, bold italic */ /* a row being drawn */ HDC row_dc; @@ -885,12 +886,21 @@ static int mods_now() return m; } +/* what is typed, on the screen too when the echo is on (not a key's + escape sequence: an arrow key does not move the cursor here) */ +static void echo_typed(TermView *t, const char *b, int n) +{ + if (t->echo && n > 0 && b[0] != 0x1b) + termview_feed(t->w, b, n); +} + static void send_key(TermView *t, int key, int mods) { char b[64]; int n = dmc_vt_key_mods(t->vt, key, mods, b, sizeof(b)); to_bottom(t); send_text(t, b, n); + echo_typed(t, b, n); } /* a character typed, as the terminal sends it */ @@ -899,6 +909,7 @@ static void send_cp(TermView *t, unsigned long cp, int mods) char b[64]; int n = dmc_vt_char_bytes(t->vt, (uint32_t)cp, mods, b, sizeof(b)); send_text(t, b, n); + echo_typed(t, b, n); } /* a character in the ANSI code page as Unicode */ @@ -1348,6 +1359,16 @@ void termview_set_backspace(HWND w, char b) dmc_vt_set_backspace(t->vt, (unsigned char)b); } +void termview_set_ascii(HWND w, int flags, int enter, bool echo) +{ + TermView *t = of(w); + if (!t) + return; + dmc_vt_set_ascii(t->vt, flags); + dmc_vt_set_enter(t->vt, enter); + t->echo = echo; +} + void termview_set_profile(HWND w, const char *id) { TermView *t = of(w); diff --git a/windows/src/xfer.cpp b/windows/src/xfer.cpp index 51ea801..284ce5d 100644 --- a/windows/src/xfer.cpp +++ b/windows/src/xfer.cpp @@ -100,14 +100,6 @@ static int ini_int(const char *key, int def) return (int)GetPrivateProfileInt("transfer", key, def, path); } -/* ASCII Setup's ([ascii]: the text's line and character delays) */ -static int ascii_int(const char *key, int def) -{ - char path[MAX_PATH]; - ini(path, sizeof(path)); - return (int)GetPrivateProfileInt("ascii", key, def, path); -} - static void ini_set(const char *key, const char *v) { char path[MAX_PATH]; @@ -799,8 +791,10 @@ void xfer_send_dialog(XferLine *l, int protocol) dmc_xfer_options o; memset(&o, 0, sizeof(o)); o.resume = a.resume; - o.line_delay_ms = ascii_int("line_delay", 0); - o.char_delay_ms = ascii_int("char_delay", 0); + AsciiSetup as; + ascii_load(&as); + o.line_delay_ms = as.line_delay; + o.char_delay_ms = as.char_delay; start(l, dmc_xfer_send_opt(a.protocol, paths, a.nfiles, &o), a.protocol, true, a.nfiles, a.resume); }