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

View File

@@ -256,8 +256,8 @@ type
CLIENT_LISTENER_START = 3'u8 # Start a listener on the TS
CLIENT_LISTENER_STOP = 4'u8 # Stop a listener
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
CLIENT_PROFILE = 100'u8 # Team server profile and configuration
CLIENT_LISTENER_ADD = 101'u8 # Add listener to listeners table