Fixed getText() function that caused text highlighting in console to break.

This commit is contained in:
Jakob Friedl
2025-10-10 12:55:50 +02:00
parent 504d15fa4d
commit 373eb497d9
2 changed files with 8 additions and 9 deletions

View File

@@ -24,10 +24,10 @@ type
]# ]#
proc getText(item: ConsoleItem): cstring = proc getText(item: ConsoleItem): cstring =
if item.timestamp > 0: if item.timestamp > 0:
let timestamp = item.timestamp.fromUnix().format("dd-MM-yyyy HH:mm:ss") let timestamp = "[" & item.timestamp.fromUnix().format("dd-MM-yyyy HH:mm:ss") & "]"
return fmt"[{timestamp}]{$item.itemType}{item.text}".string return timestamp & $item.itemType & item.text
else: else:
return fmt"{$item.itemType}{item.text}".string return $item.itemType & item.text
proc getNumLines(data: pointer): csize_t {.cdecl.} = proc getNumLines(data: pointer): csize_t {.cdecl.} =
if data.isNil: if data.isNil:
@@ -173,14 +173,12 @@ proc callback(data: ptr ImGuiInputTextCallbackData): cint {.cdecl.} =
API to add new console item API to add new console item
]# ]#
proc addItem*(component: ConsoleComponent, itemType: LogType, data: string, timestamp: int64 = now().toTime().toUnix()) = proc addItem*(component: ConsoleComponent, itemType: LogType, data: string, timestamp: int64 = now().toTime().toUnix()) =
for line in data.split("\n"): for line in data.split("\n"):
component.console.items.add(ConsoleItem( component.console.items.add(ConsoleItem(
timestamp: if itemType == LOG_OUTPUT: 0 else: timestamp, timestamp: if itemType == LOG_OUTPUT: 0 else: timestamp,
itemType: itemType, itemType: itemType,
text: line text: line
)) ))
#[ #[
Handling console commands Handling console commands
]# ]#
@@ -188,6 +186,7 @@ proc displayHelp(component: ConsoleComponent) =
for module in getModules(component.agent.modules): for module in getModules(component.agent.modules):
for cmd in module.commands: for cmd in module.commands:
component.addItem(LOG_OUTPUT, fmt" * {cmd.name:<15}{cmd.description}") component.addItem(LOG_OUTPUT, fmt" * {cmd.name:<15}{cmd.description}")
component.addItem(LOG_OUTPUT, "")
proc displayCommandHelp(component: ConsoleComponent, command: Command) = proc displayCommandHelp(component: ConsoleComponent, command: Command) =
var usage = command.name & " " & command.arguments.mapIt( var usage = command.name & " " & command.arguments.mapIt(
@@ -359,12 +358,12 @@ proc draw*(component: ConsoleComponent, connection: WsConnection) =
item.print() item.print()
component.textSelect.textselect_update()
# Auto-scroll to bottom # Auto-scroll to bottom
if igGetScrollY() >= igGetScrollMaxY(): if igGetScrollY() >= igGetScrollMaxY():
igSetScrollHereY(1.0f) igSetScrollHereY(1.0f)
component.textSelect.textselect_update()
except IndexDefect: except IndexDefect:
# CTRL+A crashes when no items are in the console # CTRL+A crashes when no items are in the console
discard discard

View File

@@ -256,8 +256,8 @@ type
CLIENT_LISTENER_START = 3'u8 # Start a listener on the TS CLIENT_LISTENER_START = 3'u8 # Start a listener on the TS
CLIENT_LISTENER_STOP = 4'u8 # Stop a listener CLIENT_LISTENER_STOP = 4'u8 # Stop a listener
CLIENT_LOOT_REMOVE = 5'u8 # Remove loot on the team server CLIENT_LOOT_REMOVE = 5'u8 # Remove loot on the team server
CLIENT_LOOT_SYNC = 6'u8 # Request to download a file/screenshot to the client CLIENT_LOOT_SYNC = 6'u8 # Download a file/screenshot to the client
# Sent by team server # Sent by team server
CLIENT_PROFILE = 100'u8 # Team server profile and configuration CLIENT_PROFILE = 100'u8 # Team server profile and configuration
CLIENT_LISTENER_ADD = 101'u8 # Add listener to listeners table CLIENT_LISTENER_ADD = 101'u8 # Add listener to listeners table