Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;┌──────────────────────────────────────────────────────────────────────┐
- ;│ BoxComment Function - AutoHotkey │
- ;│ Format comments in a box style │
- ;│ for any comment type from the Clipboard │
- ;│ or a passed comment. │
- ;│ Default comment = ';' │
- ;│ Default source = Clipboard │
- ;│ with the option to return results to Clipboard │
- ;│ or just use Send <SendRaw?>, % BoxComment() │
- ;│ Default tabconv = '4' │
- ;│ Converts tabs to spaces - if you know a better way │
- ;│ please let me know │
- ;│ E.g.: BoxComment(,"This`nis`na`nmultiline`ncomment") │
- ;│ Returns: │
- ;│ ;┌───────────┐ │
- ;│ ;│ This │ │
- ;│ ;│ is │ │
- ;│ ;│ a │ │
- ;│ ;│ multiline │ │
- ;│ ;│ comment │ │
- ;│ ;└───────────┘ │
- ;│ E.g.: BoxComment(,"This`n`tcomment`n`t`thas`n`t`ttabs") │
- ;│ Returns: │
- ;│ ;┌─────────────┐ │
- ;│ ;│ This │ │
- ;│ ;│ comment │ │
- ;│ ;│ has │ │
- ;│ ;│ tabs │ │
- ;│ ;└─────────────┘ │
- ;│ This works for: │
- ;│ Notepad │
- ;│ Notepad │
- ;│ Sublime │
- ;│ Doesn't seem to work well with: (you can use notepad and paste back) │
- ;│ Atom │
- ;│ AHK studio │
- ;└──────────────────────────────────────────────────────────────────────┘
- BoxComment(source := "clip",tabconv := 4,comment := ";",returnClip := false)
- { tabconv := IncChar(A_Space,tabconv)
- source := ( (source="clip")
- ? StrSplit(Clipboard,"`r`n",tabconv)
- : StrSplit(source,"`r`n",tabconv) )
- lenArray := {}
- for idx, line in source
- { source[idx] := StrReplace(line,A_Tab,tabconv)
- lenArray[StrLen(source[idx])] := source[idx]
- }
- line := idx := ""
- if ! (maxLen := lenArray.MaxIndex())
- return
- lenArray := ""
- padding := { "Left" : comment "│ "
- , "Right" : " │`n" }
- corners := { "TL" : comment "┌─"
- , "TR" : "─┐`n"
- , "BL" : comment "└─"
- , "BR" : "─┘" }
- loop,%maxLen%
- { line.="─"
- }
- top := corners.TL line corners.TR
- bot := corners.BL line corners.BR
- line := ""
- frmt .= top
- for idx, line in source
- { frmt .= padding.Left line IncChar(A_Space,maxLen-StrLen(line)) padding.Right
- }
- frmt .= bot
- Clipboard := returnClip?frmt:Clipboard
- return frmt
- }
- IncChar(char,inc:=2)
- { loop,%inc%
- ret.=char
- return ret
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement