Skip to content

Commit c269813

Browse files
ecliptikclaude
andcommitted
Codebase refactor and disconnect fix for v1.7.0
Major refactor: main.c reduced from 3,478 to 494 lines (86% reduction). Extracted dialogs.c, menus.c, input.c, clipboard.c, macutil.c as new modules. Data-driven key mapping, per-menu dispatch handlers, shared utilities. Removed dead code (conn_open_dialog, 6 TCP wrappers). Total compiled LOC reduced from 12,027 to 10,036 (17% reduction). Fixed remote disconnect to preserve terminal screen content instead of wiping the buffer. Window repaint after disconnect alert now works in all modes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1255138 commit c269813

32 files changed

+4579
-3821
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.7.0] - 2026-03-10
6+
7+
### Changed
8+
- Major codebase refactor: main.c reduced from 3,478 to ~494 lines (86% reduction)
9+
- Extracted dialogs.c: all dialog handling (connect, bookmarks, about, disconnect)
10+
- Extracted menus.c: menu management with per-menu dispatch handlers
11+
- Extracted input.c: keyboard/mouse handling with data-driven key mapping tables
12+
- Extracted clipboard.c: copy/paste/select all operations
13+
- Extracted macutil.c: shared utilities (c2pstr, sprintfp, set_wtitlef, clear_window_bg)
14+
- Extended session.c: font presets, ttype/font string helpers, window resize, init from prefs
15+
- Collapsed identical telnet option handlers with fallthrough in telnet.c
16+
- Extracted conn_resolve_host() from conn_connect() in connection.c
17+
- Split handle_menu() into per-menu handlers (handle_file_menu, handle_edit_menu, etc.)
18+
- Data-driven key mapping replaces if/else chain in handle_key_down()
19+
- Total compiled LOC reduced from 12,027 to 10,036 (17% reduction)
20+
21+
### Fixed
22+
- Remote disconnect preserves terminal screen content (was wiped by terminal_reset)
23+
- Window repaint after disconnect alert restores terminal content in all modes
24+
25+
### Removed
26+
- Dead conn_open_dialog() from connection.c
27+
- 6 unused TCP wrapper functions from tcp.c (~256 lines)
28+
29+
## [1.6.1] - 2026-03-10
30+
31+
### Fixed
32+
- MacTCP.h: add forward declarations for struct GetAddrParamBlock,
33+
ICMPParamBlock, TCPiopb, and UDPiopb to eliminate "declared inside
34+
parameter list" compiler warnings
35+
- tcp.h: alias proc typedefs (TCPIOCompletionProc, TCPNotifyProc, etc.)
36+
to actual MacTCP UPP types instead of incompatible ProcPtr/re-declared
37+
function pointers, eliminating all -Wincompatible-pointer-types warnings
38+
- MacTCP.h: convert from classic Mac CR to Unix LF line endings for
39+
consistent cross-platform source formatting
40+
541
## [1.6.0] - 2026-03-10
642

743
### Added

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ project(Flynn VERSION 1.6.1)
33

44
add_application(Flynn
55
src/main.c
6+
src/menus.c
7+
src/input.c
8+
src/clipboard.c
9+
src/dialogs.c
610
src/session.c
711
src/connection.c
812
src/telnet.c
@@ -11,7 +15,7 @@ add_application(Flynn
1115
src/tcp.c
1216
src/dns.c
1317
src/glyphs.c
14-
src/dnr.c
18+
src/macutil.c
1519
src/sysutil.c
1620
src/settings.c
1721
resources/telnet.r

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ No build toolchain required — just download and run.
2929
## Features
3030

3131
- **Multiple sessions** (up to 4 simultaneous windows)
32-
- **VT100/VT220/xterm terminal emulation**
33-
- **Box-drawing characters**
34-
- **Unicode glyph rendering**
35-
- **Resizable window** (80x24 up to 132x50)
32+
- **VT100/VT220/xterm/xterm-256color terminal emulation**
33+
- **Box-drawing characters, Unicode glyph rendering**
34+
- **Resizable window and scrollback** (80x24 up to 132x50)
3635
- **6 fonts** (Monaco 9/12, Courier 10, Chicago 12, Geneva 9/10)
3736
- **Session bookmarks**
38-
- **Username auto-login**
3937
- **Mouse text selection**
40-
- **Scrollback** (96 lines)
41-
- **Control menu**
4238
- **Keystroke buffering**
4339
- **M0110 keyboard support**
4440
- **Dark mode**
@@ -62,6 +58,7 @@ Flynn is designed for the Apple M0110/M0110A keyboard, which lacks Escape and Co
6258
| Extend selection | Shift+click | Extends selection to click point |
6359
| Copy | Cmd+C | Copies selection, or full screen if none |
6460
| Paste | Cmd+V | Sends clipboard to connection |
61+
| Select All | Cmd+A | Selects entire terminal screen |
6562
| F1-F10 | Cmd+1..0 | For M0110 keyboards without function keys |
6663
| Bookmarks | Cmd+B | Open bookmark manager |
6764
| New Session | Cmd+N | New session (new window if connected) |

include/MacTCP.h

Lines changed: 889 additions & 1 deletion
Large diffs are not rendered by default.

src/clipboard.c

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* clipboard.c - Clipboard operations for Flynn
3+
* Extracted from main.c
4+
*/
5+
6+
#include <Quickdraw.h>
7+
#include <Windows.h>
8+
#include <Memory.h>
9+
#include <Multiverse.h>
10+
11+
#include "main.h"
12+
#include "session.h"
13+
#include "connection.h"
14+
#include "terminal.h"
15+
#include "terminal_ui.h"
16+
#include "glyphs.h"
17+
#include "clipboard.h"
18+
19+
/* External references to main.c globals */
20+
extern Session *active_session;
21+
22+
void
23+
do_copy(void)
24+
{
25+
long buf_size;
26+
char *buf;
27+
short row, col, len, last_nonspace;
28+
TermCell *cell;
29+
Session *s = active_session;
30+
31+
if (!s)
32+
return;
33+
34+
/* Ensure global sel reflects this session's selection */
35+
term_ui_load_state(&s->ui);
36+
37+
buf_size = (long)s->terminal.active_rows *
38+
(s->terminal.active_cols + 1);
39+
buf = (char *)NewPtr(buf_size);
40+
if (!buf)
41+
return;
42+
43+
if (!term_ui_sel_active()) {
44+
DisposePtr((Ptr)buf);
45+
return;
46+
}
47+
48+
{
49+
short sr, sc, er, ec;
50+
short c_start, c_end;
51+
52+
term_ui_sel_get_range(&sr, &sc, &er, &ec);
53+
54+
len = 0;
55+
for (row = sr; row <= er; row++) {
56+
if (sr == er) {
57+
c_start = sc;
58+
c_end = ec;
59+
} else if (row == sr) {
60+
c_start = sc;
61+
c_end = s->terminal.active_cols - 1;
62+
} else if (row == er) {
63+
c_start = 0;
64+
c_end = ec;
65+
} else {
66+
c_start = 0;
67+
c_end = s->terminal.active_cols - 1;
68+
}
69+
70+
last_nonspace = -1;
71+
for (col = c_start; col <= c_end; col++) {
72+
char cc;
73+
const GlyphInfo *gi;
74+
75+
cell = terminal_get_display_cell(
76+
&s->terminal, row, col);
77+
if ((cell->attr & ATTR_GLYPH) &&
78+
cell->ch == GLYPH_WIDE_SPACER) {
79+
buf[len + (col - c_start)] = ' ';
80+
continue;
81+
}
82+
if (cell->attr & ATTR_GLYPH) {
83+
gi = glyph_get_info(cell->ch);
84+
cc = gi ? gi->copy_char : '?';
85+
} else if (cell->attr & ATTR_BRAILLE) {
86+
cc = '.';
87+
} else {
88+
cc = cell->ch;
89+
}
90+
buf[len + (col - c_start)] = cc;
91+
if (cc != ' ')
92+
last_nonspace = col - c_start;
93+
}
94+
len += last_nonspace + 1;
95+
if (row < er)
96+
buf[len++] = '\r';
97+
}
98+
}
99+
100+
ZeroScrap();
101+
PutScrap(len, 'TEXT', buf);
102+
DisposePtr((Ptr)buf);
103+
}
104+
105+
void
106+
do_paste(void)
107+
{
108+
Handle h;
109+
long offset, len;
110+
Session *s = active_session;
111+
112+
if (!s || s->conn.state != CONN_STATE_CONNECTED)
113+
return;
114+
115+
h = NewHandle(0);
116+
if (!h)
117+
return;
118+
119+
len = GetScrap(h, 'TEXT', &offset);
120+
if (len > 0) {
121+
char *p;
122+
long sent;
123+
124+
HLock(h);
125+
p = *h;
126+
127+
if (s->terminal.bracketed_paste)
128+
conn_send(&s->conn, "\033[200~", 6);
129+
130+
sent = 0;
131+
while (sent < len) {
132+
short chunk;
133+
134+
chunk = len - sent;
135+
if (chunk > 256)
136+
chunk = 256;
137+
conn_send(&s->conn, p + sent, chunk);
138+
sent += chunk;
139+
}
140+
141+
if (s->terminal.bracketed_paste)
142+
conn_send(&s->conn, "\033[201~", 6);
143+
144+
HUnlock(h);
145+
}
146+
DisposeHandle(h);
147+
}
148+
149+
void
150+
do_select_all(void)
151+
{
152+
Session *s = active_session;
153+
154+
if (!s || s->conn.state != CONN_STATE_CONNECTED)
155+
return;
156+
157+
term_ui_sel_start(0, 0, 0);
158+
term_ui_sel_extend(s->terminal.active_rows - 1,
159+
s->terminal.active_cols - 1, &s->terminal);
160+
term_ui_sel_finalize();
161+
term_ui_sel_dirty_all(&s->terminal);
162+
163+
{
164+
GrafPtr save;
165+
166+
GetPort(&save);
167+
SetPort(s->window);
168+
term_ui_draw(s->window, &s->terminal);
169+
SetPort(save);
170+
}
171+
172+
/* Need to update menus to reflect selection state.
173+
* Call through extern since menus.c owns this. */
174+
{
175+
extern void update_menus(void);
176+
update_menus();
177+
}
178+
}

src/clipboard.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* clipboard.h - Clipboard operations for Flynn
3+
* Extracted from main.c
4+
*/
5+
6+
#ifndef CLIPBOARD_H
7+
#define CLIPBOARD_H
8+
9+
/* Copy selected text to system clipboard */
10+
void do_copy(void);
11+
12+
/* Paste system clipboard into active session */
13+
void do_paste(void);
14+
15+
/* Select all text in active session */
16+
void do_select_all(void);
17+
18+
#endif /* CLIPBOARD_H */

0 commit comments

Comments
 (0)