Skip to content

cursor_x and cursor_y properties on Terminal #10442

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

Merged
merged 1 commit into from
Jun 25, 2025
Merged
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
28 changes: 27 additions & 1 deletion shared-bindings/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ static mp_uint_t terminalio_terminal_write(mp_obj_t self_in, const void *buf_in,
return common_hal_terminalio_terminal_write(self, buf, size, errcode);
}

//| cursor_x: int
//| """The x position of the cursor."""
//|
static mp_obj_t terminalio_terminal_obj_get_cursor_x(mp_obj_t self_in) {
terminalio_terminal_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_terminalio_terminal_get_cursor_x(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(terminalio_terminal_get_cursor_x_obj, terminalio_terminal_obj_get_cursor_x);

MP_PROPERTY_GETTER(terminalio_terminal_cursor_x_obj,
(mp_obj_t)&terminalio_terminal_get_cursor_x_obj);

//| cursor_y: int
//| """The y position of the cursor."""
//|
static mp_obj_t terminalio_terminal_obj_get_cursor_y(mp_obj_t self_in) {
terminalio_terminal_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_terminalio_terminal_get_cursor_y(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(terminalio_terminal_get_cursor_y_obj, terminalio_terminal_obj_get_cursor_y);

MP_PROPERTY_GETTER(terminalio_terminal_cursor_y_obj,
(mp_obj_t)&terminalio_terminal_get_cursor_y_obj);

static mp_uint_t terminalio_terminal_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
terminalio_terminal_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t ret;
Expand All @@ -155,6 +179,8 @@ static mp_uint_t terminalio_terminal_ioctl(mp_obj_t self_in, mp_uint_t request,
static const mp_rom_map_elem_t terminalio_terminal_locals_dict_table[] = {
// Standard stream methods.
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_cursor_x), MP_ROM_PTR(&terminalio_terminal_cursor_x_obj) },
{ MP_ROM_QSTR(MP_QSTR_cursor_y), MP_ROM_PTR(&terminalio_terminal_cursor_y_obj) },
};
static MP_DEFINE_CONST_DICT(terminalio_terminal_locals_dict, terminalio_terminal_locals_dict_table);

Expand All @@ -168,7 +194,7 @@ static const mp_stream_p_t terminalio_terminal_stream_p = {
MP_DEFINE_CONST_OBJ_TYPE(
terminalio_terminal_type,
MP_QSTR_Terminal,
MP_TYPE_FLAG_ITER_IS_ITERNEXT,
MP_TYPE_FLAG_ITER_IS_ITERNEXT | MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS,
make_new, terminalio_terminal_make_new,
locals_dict, (mp_obj_dict_t *)&terminalio_terminal_locals_dict,
iter, mp_stream_unbuffered_iter,
Expand Down
3 changes: 3 additions & 0 deletions shared-bindings/terminalio/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ extern void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *
extern size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self,
const uint8_t *data, size_t len, int *errcode);

extern uint16_t common_hal_terminalio_terminal_get_cursor_x(terminalio_terminal_obj_t *self);
extern uint16_t common_hal_terminalio_terminal_get_cursor_y(terminalio_terminal_obj_t *self);

extern bool common_hal_terminalio_terminal_ready_to_tx(terminalio_terminal_obj_t *self);
7 changes: 7 additions & 0 deletions shared-module/terminalio/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
return i - data;
}

uint16_t common_hal_terminalio_terminal_get_cursor_x(terminalio_terminal_obj_t *self) {
return self->cursor_x;
}
uint16_t common_hal_terminalio_terminal_get_cursor_y(terminalio_terminal_obj_t *self) {
return self->cursor_y;
}

bool common_hal_terminalio_terminal_ready_to_tx(terminalio_terminal_obj_t *self) {
return self->scroll_area != NULL;
}
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