@@ -35,6 +35,7 @@ import imgui.ImGui.setScrollHereY
3535import imgui.ImGui.smallButton
3636import imgui.ImGui.style
3737import imgui.ImGui.textEx
38+ import imgui.ImGui.textUnformatted
3839import imgui.ImGui.textWrapped
3940import imgui.classes.InputTextCallbackData
4041import imgui.classes.TextFilter
@@ -74,7 +75,7 @@ object Console {
7475 fun clearLog () = items.clear()
7576
7677 fun addLog (fmt : String , vararg args : Any ) {
77- items.add( fmt.format(* args) )
78+ items + = fmt.format(* args)
7879 }
7980
8081 fun draw (title : String , pOpen : KMutableProperty0 <Boolean >) {
@@ -159,7 +160,7 @@ object Console {
159160 pushStyleColor(Col .Text , Vec4 (1f , 0.8f , 0.6f , 1f ))
160161 popColor = true
161162 }
162- textEx (i)
163+ textUnformatted (i)
163164 if (popColor)
164165 popStyleColor()
165166 }
@@ -175,15 +176,10 @@ object Console {
175176
176177 var reclaimFocus = false
177178 if (inputText(" Input" , inputBuf, Itf .EnterReturnsTrue .i or Itf .CallbackCompletion .i or Itf .CallbackHistory .i, textEditCallbackStub, this )) {
178- TODO ()
179- // val slen = inputBuf.textStr(inputBuf)
180- // val s = String(inputBuf.copyOf(slen)).split(" ")[0]
181- // if (s.isNotEmpty())
182- // execCommand(s)
183- // for (i in 0 until slen)
184- // inputBuf[i] = NUL
185- //
186- // reclaimFocus = true
179+ val s = String (inputBuf).trimEnd()
180+ if (s.isNotEmpty())
181+ execCommand(s)
182+ reclaimFocus = true
187183 }
188184
189185 setItemDefaultFocus()
@@ -194,27 +190,29 @@ object Console {
194190 }
195191
196192 fun execCommand (cmdLine : String ) {
197- addLog(" # %s \n " , cmdLine )
193+ addLog(" # $cmdLine \n " )
198194
195+ // Insert into history. First find match and delete it so it can be pushed to the back. This isn't trying to be smart or optimal.
199196 historyPos = - 1
200- history.remove(cmdLine) // could be at any pos, we only want it to be last. so we remove the current instance
201- history.add( cmdLine)
197+ history - = cmdLine
198+ history + = cmdLine
202199
203- when (cmdLine) {
200+ // Process command
201+ when (cmdLine.toUpperCase()) {
204202 " CLEAR" -> clearLog()
205203 " HELP" -> {
206204 addLog(" Commands:" )
207- commands.forEach { addLog(" - %s " , it ) }
205+ commands.forEach { addLog(" - $it " ) }
208206 }
209207 " HISTORY" -> {
210208 val first = history.size - 10
211209 for (i in (if (first > 0 ) first else 0 ) until history.size)
212- addLog(" %3d: %s \n " , i, history[i] )
210+ addLog(" %3d: ${history[i]} \n " , i)
213211 }
214- else -> addLog(" Unknown command: '%s '\n " , cmdLine )
212+ else -> addLog(" Unknown command: '$cmdLine '\n " )
215213 }
216214
217- // On commad input, we scroll to bottom even if AutoScroll==false
215+ // On command input, we scroll to bottom even if AutoScroll==false
218216 scrollToBottom = true
219217 }
220218
0 commit comments