Skip to content

Commit 8fca4a8

Browse files
committed
+ Display response as HTML/Markdown in popup viewer
1 parent 301fa1c commit 8fca4a8

File tree

6 files changed

+937
-9
lines changed

6 files changed

+937
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
settings.ini
22
settings.ini.x
33
AI-Tools.exe
4-
*.log
4+
*.log
5+
.vscode/settings.json

AI-Tools.ahk

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#singleInstance force
77
#Include "_jxon.ahk"
88
#include "_Cursor.ahk"
9+
#Include "_MD2HTML.ahk"
910

1011
Persistent
1112
SendMode "Input"
@@ -118,7 +119,7 @@ GetTextFromClip() {
118119

119120
if StrLen(text) < 1 {
120121
throw ValueError("No text selected", -1)
121-
} else if StrLen(text) > 2048 {
122+
} else if StrLen(text) > 16000 {
122123
throw ValueError("Text is too long", -1)
123124
}
124125

@@ -217,6 +218,16 @@ CallAPI(mode, promptName, prompt, input, promptEnd) {
217218

218219
HandleResponse(data, mode, promptName, input) {
219220

221+
Gui_Size(thisGui, MinMax, Width, Height)
222+
{
223+
if MinMax = -1 ; The window has been minimized. No action needed.
224+
return
225+
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
226+
;xEdit.Move(,, Width-30, Height-55)
227+
ogcActiveXWBC.Move(,, Width-30, Height-55)
228+
xClose.Move(Width/2 - 40,Height-40,,)
229+
}
230+
220231
try {
221232

222233
LogDebug "data ->`n" data
@@ -249,13 +260,34 @@ HandleResponse(data, mode, promptName, input) {
249260
}
250261
}
251262

252-
if _displayResponse {
263+
response_type := GetSetting(promptName, "response_type", "")
264+
if _displayResponse or response_type == "popup" {
253265
MyGui := Gui(, "Response")
254-
MyGui.SetFont("s14")
266+
MyGui.SetFont("s13")
255267
MyGui.Opt("+AlwaysOnTop +Owner +Resize") ; +Owner avoids a taskbar button.
256-
MyGui.Add("Edit", "r20 vMyEdit w600 Wrap", text)
257-
MyGui.Add("Button", , "Close").OnEvent("Click", (*) => WinClose())
258-
MyGui.Show("NoActivate")
268+
269+
ogcActiveXWBC := MyGui.Add("ActiveX", "xm w800 h480 vIE", "Shell.Explorer")
270+
WB := ogcActiveXWBC.Value
271+
WB.Navigate("about:blank")
272+
css := FileRead("style.css")
273+
options := {css:css
274+
, font_name:"Segoe UI"
275+
, font_size:16
276+
, font_weight:400
277+
, line_height:"1.6"} ; 1.6em - put decimals in "" for easier accuracy/handling.
278+
html := make_html(text, options, false)
279+
WB.document.write(html)
280+
281+
;xEdit := MyGui.Add("Edit", "r10 vMyEdit w800 Wrap", text)
282+
;xEdit.Value .= "`n`n----`n`n" html
283+
284+
xClose := MyGui.Add("Button", "Default w80", "Close")
285+
xClose.OnEvent("Click", (*) => WinClose())
286+
287+
MyGui.Show("NoActivate AutoSize Center")
288+
MyGui.GetPos(&x,&y,&w,&h)
289+
xClose.Move(w/2 - 40,,,)
290+
MyGui.OnEvent("Size", Gui_Size)
259291
} else {
260292
WinActivate _activeWin
261293
A_Clipboard := text

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Elijah Cornell
3+
Copyright (c) 2024 Elijah Cornell
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ Tested on Windows 10 Pro 22H2 64-bit.
7272

7373
## Credits
7474

75-
TheArkive (JXON_ahk2), iseahound (SetSystemCursor), and the AHK community.
75+
TheArkive (JXON_ahk2, M-ArkDown_ahk2), iseahound (SetSystemCursor), and the AHK community.
7676

7777
- https://github.com/iseahound/SetSystemCursor
7878
- https://github.com/TheArkive/JXON_ahk2
79+
- https://github.com/TheArkive/M-ArkDown_ahk2
7980

0 commit comments

Comments
 (0)