TextAnalysisTool / Releases

Repository for storing release artifacts (ex: binaries).
88 stars 26 forks source link

Clickable links / file paths #56

Open eladavron opened 5 years ago

eladavron commented 5 years ago

A lot of time in logs we get links and file paths which it would be useful to be able to click. For example, if a line has the text: An errorlog was saved to c:\foo\bar.log or Please see http://www.foo.bar for more details, it would be useful to be able to click and/or copy just those paths as opposed to the entire line.

vincec-msft commented 5 years ago

This is a good idea. I can see a couple different ways it could manifest:

  1. The links are "hot" in the display and clicking on them immediately invokes the shell handler. Pro: quick access. Con: would probably have to be limited to a URI format so something like c:\foo.txt wouldn't work but file://c:\foo.txt would. Another con is performance in that we'd have to parse each line and have more custom drawing if a link was found.

  2. A feature to copy a subset of the line as selected by what's right-clicked on. The downside here is that defining the correct subset would be impossible (your definition of the right subset might be different than your colleague's) and it would rely on the mouse.

  3. A feature to copy a regex from a line. The list of regexes (regexi?) could be limited for the simple version or user-defined/extensible for the fancy version. In either case we'd have to handle the case where there are multiple instances of the regex in the line. But at least we wouldn't have to parse every line on the off-chance there might be an interesting token. This is also nice because tokens other than links could be defined (guids, server names, etc).

As you can probably tell, I'm leaning toward Option 3. But I'd like to hear if there are other opinions/ideas.

vincec-msft commented 5 years ago

In the meantime, I offer this script using another on of my favorite tools, AutoHotKey.

This script stays resident waiting for you to press Windows+Ctrl+C with the TextAnalysisTool.NET window active. When you do it looks for a URI (yes, just the first one for this quick hack). If it finds one then it copies just that URI to the clipboard. You can also uncomment the Run line to have it automatically invoke the shell handler for that protocol.

This doesn't mean TextAnalysisTool.NET won't do what you want, I just wanted to offer another avenue.

#noenv
#SingleInstance force

;;-----------------------------------------------------------------------------------------
; This is an AutoHotKey script. You can install AHK from here: http://ahkscript.org/
; Download link: https://autohotkey.com/download/
;;-----------------------------------------------------------------------------------------

; This hotkey will only work in TextAnalysisTool.NET. Comment the next line and
; the #IfWinActive line further down to have it active in all windows.
#IfWinActive, ahk_exe TextAnalysisTool.NET.exe

;;
;;    Windows + Ctrl + C -- Copy and trim to regex
;;
^#c::
selection := GetSelectedText()

; See https://www.autohotkey.com/docs/commands/RegExMatch.htm
; O) tells RegExMatch to store a match object in the output variable (match)
if (RegExMatch(selection, "O)([\w]+://[^\s]+)", match) > 0)
{
    selection := match.Value(1)

    ; Invoke the shell handler for the trimmed text
    ;Run, %selection%
}

;OutputDebug, % "selection = [" selection "]"

; Copy the trimmed text to the clipboard
Clipboard := selection

return

#IfWinActive        ; Restore "all apps" behavior

GetSelectedText()
{
    ; Save what's on the clipboard
    clipboardSaved := ClipboardAll

    ; Start off empty to allow ClipWait to detect when the text has arrived.
    str =
    clipboard =
    Send ^c
    ; Wait for the clipboard to contain text.
    ClipWait, 1, 1
    if ErrorLevel
    {
        OutputDebug, "No text was copied."
        ErrorLevel := 1
    }
    else
    {
        str := clipboard
    }

    ; Restore the clipboard
    Clipboard := clipboardSaved
    clipboardSaved =    ; Free the memory in case the clipboard was very large

    return str
}