Skip to content

Commit 27ca057

Browse files
refactor: dont repeat the kpeek 27 && ctrl
1 parent 2ae5b51 commit 27ca057

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

include/basic/console.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,6 @@ int64_t basic_capslock(struct basic_ctx* ctx);
248248
*
249249
* @param ctx The interpreter context.
250250
*/
251-
void sleep_statement(struct basic_ctx* ctx);
251+
void sleep_statement(struct basic_ctx* ctx);
252+
253+
bool basic_esc();

src/basic/console.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int64_t basic_capslock(struct basic_ctx* ctx)
7070
*/
7171
bool check_input_in_progress(process_t* proc, void* opaque)
7272
{
73-
if (kpeek() == 27 && ctrl_held()) {
73+
if (basic_esc()) {
7474
return false;
7575
}
7676
return kinput(10240) == 0;
@@ -344,7 +344,7 @@ void kget_statement(struct basic_ctx* ctx)
344344

345345
bool check_sleep_in_progress(process_t* proc, [[maybe_unused]] void* opaque)
346346
{
347-
if (kpeek() == 27 && ctrl_held()) {
347+
if (basic_esc()) {
348348
return false;
349349
}
350350
return time(NULL) < proc->code->sleep_until;

src/basic/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,13 +854,17 @@ void line_statement(struct basic_ctx* ctx)
854854
statement(ctx);
855855
}
856856

857+
bool basic_esc() {
858+
return (kpeek() == 27 && ctrl_held());
859+
}
860+
857861
void basic_run(struct basic_ctx* ctx)
858862
{
859863
if (basic_finished(ctx)) {
860864
return;
861865
}
862866
/* TODO Make sure this only runs for foreground processes! */
863-
if (kpeek() == 27 && ctrl_held() && !ctx->errored) {
867+
if (basic_esc() && !ctx->errored) {
864868
(void)kgetc();
865869
tokenizer_error_print(ctx, "Escape");
866870
}

src/basic/sockets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
bool check_sockread_ready(process_t* proc, void* ptr) {
1818
int64_t fd = (int64_t)(uintptr_t)ptr;
19-
if (kpeek() == 27 && ctrl_held()) {
19+
if (basic_esc()) {
2020
return false;
2121
}
2222
return !sock_ready_to_read((int)fd);

0 commit comments

Comments
 (0)