Skip to content
Open
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
52 changes: 51 additions & 1 deletion src/studio/screens/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -4003,7 +4003,9 @@ static void processConsoleCommand(Console* console)

if(commandSize)
{
#ifdef BAREMETALPI
printf("%s", console->input.text);
#endif
Comment on lines +4006 to +4008

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this proposed request makes a sync between tic80 console and the system console, we have to remove the output here, otherwise we get a duplicated command output.

appendHistory(console, console->input.text);
processCommand(console, console->input.text);
}
Expand Down Expand Up @@ -4271,6 +4273,26 @@ static void backspaceWord(Console* console)
console->input.pos = pos;
}

static void refreshTerminal(Console* console)
{
#ifndef BAREMETALPI
if (!console->args.cli)
{
char dir[TICNAME_MAX];
tic_fs_dir(console->fs, dir);
printf("\r\033[K");
if(strlen(dir))
printf("%s", dir);
printf(">%s", console->input.text);

s32 tailLen = (s32)strlen(console->input.text) - (s32)console->input.pos;
if (tailLen > 0)
printf("\033[%dD", tailLen);
fflush(stdout);
}
#endif
}

static void processKeyboard(Console* console)
{
tic_mem* tic = console->tic;
Expand Down Expand Up @@ -4356,6 +4378,7 @@ static void processKeyboard(Console* console)
console->cursor.delay = CONSOLE_CURSOR_DELAY;
}

refreshTerminal(console);
}

static void processGamepad(Console* console)
Expand All @@ -4376,7 +4399,6 @@ static void tick(Console* console)
tic_mem* tic = console->tic;

processMouse(console);
processKeyboard(console);
processGamepad(console);

Start* start = getStartScreen(console->studio);
Expand All @@ -4402,6 +4424,8 @@ static void tick(Console* console)
else printBack(console, "\n loading cart...");
}

processKeyboard(console);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move it down here because it was causing an extra > at the startup:


 TIC-80 tiny computer
 version 1.2.3101-dev (240d0a1)
 https://tic80.com (C) 2017-2026
>
 hello! type help for help

>


tic_api_cls(tic, TIC_COLOR_BG);
drawConsoleText(console);

Expand Down Expand Up @@ -4541,6 +4565,32 @@ static int apicmp(const void* a, const void* b)
return strcmp(((const ApiItem*)a)->name, ((const ApiItem*)b)->name);
}

// Handle terminal input events directly, bypassing the regular SDL event loop for some keys.
// This allows commands to be entered and executed even when the console is in the background.
void console_terminal_input(Console* console, tic_key key, char text)
{
if(key == tic_key_return)
{
processConsoleCommand(console);
while(console->commands.current < console->commands.count)
{
const char* command = console->commands.items[console->commands.current];
processCommand(console, command);
console->commands.current++;
}
}
else if(key == tic_key_backspace) processConsoleBackspace(console);
else if(key == tic_key_tab) processConsoleTab(console);
else if(key == tic_key_delete) processConsoleDel(console);
else if(key == tic_key_up) onHistoryUp(console);
else if(key == tic_key_down) onHistoryDown(console);
else if(key == tic_key_left) { if(console->input.pos > 0) console->input.pos--; }
else if(key == tic_key_right) { console->input.pos++; s32 len = (s32)strlen(console->input.text); if(console->input.pos > len) console->input.pos = (size_t)len; }
else if(text) insertInputText(console, (char[]){text, '\0'});

refreshTerminal(console);
}

void initConsole(Console* console, Studio* studio, tic_fs* fs, tic_net* net, Config* config, StartArgs args)
{
if(!console->text) console->text = malloc(CONSOLE_BUFFER_SIZE);
Expand Down
1 change: 1 addition & 0 deletions src/studio/screens/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ struct Console

void initConsole(Console*, Studio* studio, struct tic_fs* fs, struct tic_net* net, struct Config* config, StartArgs args);
void freeConsole(Console* console);
void console_terminal_input(Console* console, tic_key key, char text);
void forceAutoSave(Console* console, const char* cart_name);
1 change: 1 addition & 0 deletions src/studio/screens/console_minimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ void freeConsole(Console* console)
}

void forceAutoSave(Console* console, const char* cart_name) {}
void console_terminal_input(Console* console, tic_key key, char text) {}
5 changes: 5 additions & 0 deletions src/studio/studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,11 @@ bool checkStudioViMode(Studio* studio, ViMode mode) {
}
#endif

void studio_terminal_input(Studio* studio, tic_key key, char text)
{
console_terminal_input(studio->console, key, text);
}

static inline bool pointInRect(const tic_point* pt, const tic_rect* rect)
{
return (pt->x >= rect->x)
Expand Down
1 change: 1 addition & 0 deletions src/studio/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void exitStudio(Studio* studio);
void setStudioViMode(Studio* studio, ViMode mode);
ViMode getStudioViMode(Studio* studio);
bool checkStudioViMode(Studio* studio, ViMode mode);
void studio_terminal_input(Studio* studio, tic_key key, char text);

void toClipboard(const void* data, s32 size, bool flip);
bool fromClipboard(void* data, s32 size, bool flip, bool remove_white_spaces, bool sameSize);
Expand Down
Loading
Loading