Skip to content

Commit a8bb645

Browse files
larsbrinkhoffsgtatham
authored andcommitted
Add a new seat method to return the cursor position.
The motivation is for the SUPDUP protocol. The server may send a signal for the terminal to reset any input buffers. After this, the server will not know the state of the terminal, so it is required to send its cursor position back.
1 parent 1efded2 commit a8bb645

File tree

11 files changed

+44
-0
lines changed

11 files changed

+44
-0
lines changed

misc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ bool nullseat_verbose_no(Seat *seat) { return false; }
368368
bool nullseat_verbose_yes(Seat *seat) { return true; }
369369
bool nullseat_interactive_no(Seat *seat) { return false; }
370370
bool nullseat_interactive_yes(Seat *seat) { return true; }
371+
bool nullseat_get_cursor_position(Seat *seat, int *x, int *y) { return false; }
371372

372373
bool null_lp_verbose_no(LogPolicy *lp) { return false; }
373374
bool null_lp_verbose_yes(LogPolicy *lp) { return true; }

pscp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static const SeatVtable pscp_seat_vt = {
8383
nullseat_set_trust_status_vacuously,
8484
cmdline_seat_verbose,
8585
nullseat_interactive_no,
86+
nullseat_get_cursor_position,
8687
};
8788
static Seat pscp_seat[1] = {{ &pscp_seat_vt }};
8889

psftp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static const SeatVtable psftp_seat_vt = {
6565
nullseat_set_trust_status_vacuously,
6666
cmdline_seat_verbose,
6767
nullseat_interactive_yes,
68+
nullseat_get_cursor_position,
6869
};
6970
static Seat psftp_seat[1] = {{ &psftp_seat_vt }};
7071

putty.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,13 @@ struct SeatVtable {
918918
* Ask the seat whether it's an interactive program.
919919
*/
920920
bool (*interactive)(Seat *seat);
921+
922+
/*
923+
* Return the seat's current idea of where the output cursor is.
924+
*
925+
* Returns true if the seat has a cursor. Returns false if not.
926+
*/
927+
bool (*get_cursor_position)(Seat *seat, int *x, int *y);
921928
};
922929

923930
static inline size_t seat_output(
@@ -967,6 +974,8 @@ static inline bool seat_verbose(Seat *seat)
967974
{ return seat->vt->verbose(seat); }
968975
static inline bool seat_interactive(Seat *seat)
969976
{ return seat->vt->interactive(seat); }
977+
static inline bool seat_get_cursor_position(Seat *seat, int *x, int *y)
978+
{ return seat->vt->get_cursor_position(seat, x, y); }
970979

971980
/* Unlike the seat's actual method, the public entry point
972981
* seat_connection_fatal is a wrapper function with a printf-like API,
@@ -1023,6 +1032,7 @@ bool nullseat_verbose_no(Seat *seat);
10231032
bool nullseat_verbose_yes(Seat *seat);
10241033
bool nullseat_interactive_no(Seat *seat);
10251034
bool nullseat_interactive_yes(Seat *seat);
1035+
bool nullseat_get_cursor_position(Seat *seat, int *x, int *y);
10261036

10271037
/*
10281038
* Seat functions provided by the platform's console-application
@@ -1607,6 +1617,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
16071617
void term_set_trust_status(Terminal *term, bool trusted);
16081618
void term_keyinput(Terminal *, int codepage, const void *buf, int len);
16091619
void term_keyinputw(Terminal *, const wchar_t * widebuf, int len);
1620+
void term_get_cursor_position(Terminal *term, int *x, int *y);
16101621

16111622
typedef enum SmallKeypadKey {
16121623
SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,

sesschan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ static const SeatVtable sesschan_seat_vt = {
199199
nullseat_set_trust_status,
200200
nullseat_verbose_no,
201201
nullseat_interactive_no,
202+
nullseat_get_cursor_position,
202203
};
203204

204205
Channel *sesschan_new(SshChannel *c, LogContext *logctx,

sshserver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static const SeatVtable server_seat_vt = {
122122
nullseat_set_trust_status,
123123
nullseat_verbose_no,
124124
nullseat_interactive_no,
125+
nullseat_get_cursor_position,
125126
};
126127

127128
static void server_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,

terminal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,12 @@ void term_set_trust_status(Terminal *term, bool trusted)
18101810
term->trusted = trusted;
18111811
}
18121812

1813+
void term_get_cursor_position(Terminal *term, int *x, int *y)
1814+
{
1815+
*x = term->curs.x;
1816+
*y = term->curs.y;
1817+
}
1818+
18131819
/*
18141820
* Set up the terminal for a given size.
18151821
*/

unix/gtkwin.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ static const char *gtk_seat_get_x_display(Seat *seat);
373373
static bool gtk_seat_get_windowid(Seat *seat, long *id);
374374
#endif
375375
static bool gtk_seat_set_trust_status(Seat *seat, bool trusted);
376+
static bool gtk_seat_get_cursor_position(Seat *seat, int *x, int *y);
376377

377378
static const SeatVtable gtk_seat_vt = {
378379
gtk_seat_output,
@@ -399,6 +400,7 @@ static const SeatVtable gtk_seat_vt = {
399400
gtk_seat_set_trust_status,
400401
nullseat_verbose_yes,
401402
nullseat_interactive_yes,
403+
gtk_seat_get_cursor_position,
402404
};
403405

404406
static void gtk_eventlog(LogPolicy *lp, const char *string)
@@ -5530,3 +5532,13 @@ static bool gtk_seat_set_trust_status(Seat *seat, bool trusted)
55305532
term_set_trust_status(inst->term, trusted);
55315533
return true;
55325534
}
5535+
5536+
static bool gtk_seat_get_cursor_position(Seat *seat, int *x, int *y)
5537+
{
5538+
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
5539+
if (inst->term) {
5540+
term_get_cursor_position(inst->term, x, y);
5541+
return true;
5542+
}
5543+
return false;
5544+
}

unix/uxplink.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static const SeatVtable plink_seat_vt = {
407407
console_set_trust_status,
408408
cmdline_seat_verbose,
409409
plink_seat_interactive,
410+
nullseat_get_cursor_position,
410411
};
411412
static Seat plink_seat[1] = {{ &plink_seat_vt }};
412413

windows/window.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ static void win_seat_connection_fatal(Seat *seat, const char *msg);
336336
static void win_seat_update_specials_menu(Seat *seat);
337337
static void win_seat_set_busy_status(Seat *seat, BusyStatus status);
338338
static bool win_seat_set_trust_status(Seat *seat, bool trusted);
339+
static bool win_seat_get_cursor_position(Seat *seat, int *x, int *y);
339340

340341
static const SeatVtable win_seat_vt = {
341342
win_seat_output,
@@ -358,6 +359,7 @@ static const SeatVtable win_seat_vt = {
358359
win_seat_set_trust_status,
359360
nullseat_verbose_yes,
360361
nullseat_interactive_yes,
362+
win_seat_get_cursor_position,
361363
};
362364
static WinGuiSeat wgs = { .seat.vt = &win_seat_vt,
363365
.logpolicy.vt = &win_gui_logpolicy_vt };
@@ -5801,3 +5803,9 @@ static bool win_seat_set_trust_status(Seat *seat, bool trusted)
58015803
term_set_trust_status(term, trusted);
58025804
return true;
58035805
}
5806+
5807+
static bool win_seat_get_cursor_position(Seat *seat, int *x, int *y)
5808+
{
5809+
term_get_cursor_position(term, x, y);
5810+
return true;
5811+
}

0 commit comments

Comments
 (0)