2018-01-13 14:43:12 +00:00
|
|
|
/*
|
|
|
|
:title: bug.n -- tiling window management
|
|
|
|
:copyright: (c) 2010-2017 by Joshua Fuhs, joten <https://github.com/joten>
|
2019-04-07 19:11:56 +00:00
|
|
|
:license: GNU General Public License version 3; for more details:
|
2018-01-13 14:43:12 +00:00
|
|
|
../LICENSE.md or at <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
;; script settings
|
|
|
|
#NoEnv ;; Recommended for performance and compatibility with future AutoHotkey releases.
|
|
|
|
SendMode Input ;; Recommended for new scripts due to its superior speed and reliability.
|
|
|
|
SetBatchLines, -1
|
|
|
|
SetControlDelay, 0
|
|
|
|
SetTitleMatchMode, 3
|
|
|
|
SetTitleMatchMode, Fast
|
|
|
|
SetWorkingDir %A_ScriptDir% ;; Ensures a consistent starting directory.
|
|
|
|
#SingleInstance Force
|
|
|
|
;#Warn ;; Enable warnings to assist with detecting common errors.
|
|
|
|
|
|
|
|
;; pseudo main function
|
|
|
|
M_NAME := "bug.n"
|
2019-04-07 19:28:37 +00:00
|
|
|
M_VERSION := "9.1.0"
|
2018-01-13 14:43:12 +00:00
|
|
|
Progress,,,, Building %M_NAME%
|
|
|
|
M_logLevel := 5 ;; higher values mean more logging, type = int, choices = [0, 1, 2, 3, 4, 5, 6], default = 5
|
|
|
|
|
|
|
|
_log := new Logging(A_ScriptDir . "\log-build-" . A_ComputerName . "_" . A_UserName . ".md",, M_logLevel)
|
|
|
|
_log.message("Building " . M_NAME . " started", 4)
|
|
|
|
Progress, 10
|
|
|
|
|
|
|
|
compile(A_ScriptDir . "\..\src\Main.ahk", A_ScriptDir . "\..\bugn.exe", A_ScriptDir . "\..\src\logo.ico")
|
2018-01-13 21:19:16 +00:00
|
|
|
Progress, 70
|
|
|
|
|
|
|
|
createCheatSheet(A_ScriptDir . "\..\doc\Default_hotkeys.md", A_ScriptDir . "\..\doc\Cheat_sheet")
|
2018-01-13 14:43:12 +00:00
|
|
|
Progress, 100
|
|
|
|
|
|
|
|
_log.message("Building " . M_NAME . " finished", 0)
|
2018-01-13 21:19:16 +00:00
|
|
|
Sleep, 500
|
2018-01-13 14:43:12 +00:00
|
|
|
Progress, OFF
|
|
|
|
Return
|
|
|
|
;; end of the auto-execute section
|
|
|
|
|
|
|
|
;; class, function & label definitions
|
|
|
|
class Logging {
|
|
|
|
__New(file, truncate := True, level := 0) {
|
|
|
|
this.file := file
|
|
|
|
this.level := level ? level : 6
|
|
|
|
this.label := StrSplit(";CRITICAL;ERROR;WARNING;INFO;DEBUG;SUPER", ";")
|
|
|
|
|
|
|
|
If (truncate && FileExist(this.file)) {
|
|
|
|
FileDelete, % this.file
|
|
|
|
this.message("**Logging.__New**: File deleted (``" . this.file . "``)", 3)
|
|
|
|
}
|
|
|
|
FormatTime, timestamp, , yyyy-MM-dd
|
|
|
|
FileAppend, % "`r`n# " . timestamp . "`r`n", % this.file
|
|
|
|
this.message("Logging started with log level " . this.level, 4)
|
|
|
|
}
|
|
|
|
|
|
|
|
message(text, level, timestamp := True) { ;; level = 0: log in any case
|
|
|
|
If (this.level >= level) {
|
|
|
|
If timestamp
|
|
|
|
FormatTime, timestamp, , yyyy-MM-dd HH:mm:ss
|
|
|
|
i := level + 1
|
|
|
|
text := StrPad(timestamp, " ", 19) . "> " . StrPad(this.label[i], ".", 8) . ": " . text . "`r`n"
|
|
|
|
FileAppend, % text, % this.file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setLevel(d, level := 0) {
|
|
|
|
level := level ? level : this.level
|
|
|
|
level := IntMin(IntMax(level + d, 1), 6)
|
|
|
|
If (level != this.level) {
|
|
|
|
this.level := level
|
|
|
|
i := level + 1
|
|
|
|
this.message("Log level set to " . this.label[i], 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compile(source, destination, customIcon, compiler := "C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe", compressor := "C:\Program Files\AutoHotkey\Compiler\mpress.exe") {
|
|
|
|
Global _log
|
|
|
|
|
2018-04-28 19:38:02 +00:00
|
|
|
useMpress := FileExist(compressor) ? "1" : "0"
|
2018-01-13 21:19:16 +00:00
|
|
|
_log.message("**compile**: Variable set, source -> ``" . source . "``, the file does " . (FileExist(source) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**compile**: Variable set, destination -> ``" . destination . "``, the file does " . (FileExist(destination) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**compile**: Variable set, customIcon -> ``" . customIcon . "``, the file does " . (FileExist(customIcon) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**compile**: Variable set, compiler -> ``" . compiler . "``, the file does " . (FileExist(compiler) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**compile**: Variable set, useMpress -> ``" . useMpress . "``", 5)
|
2018-01-13 14:43:12 +00:00
|
|
|
If (FileExist(source) && FileExist(compiler))
|
|
|
|
RunWait, %compiler% /in %source% /icon %customIcon% /mpress %useMpress% /out %destination%
|
|
|
|
_log.message("Compiling the script to an executable finished.", 4)
|
2019-04-07 19:11:56 +00:00
|
|
|
If (!FileExist(destination)) {
|
|
|
|
_log.message("**compile**: Resulting file ``" . destination . "`` does not exist.", 2)
|
|
|
|
}
|
2018-01-13 14:43:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 19:11:56 +00:00
|
|
|
createCheatSheet(source, destDir, filename := "cheat_sheet", converter := "") {
|
2018-01-15 16:42:55 +00:00
|
|
|
Global _log, M_NAME, M_VERSION
|
2018-01-13 21:19:16 +00:00
|
|
|
|
2019-04-07 19:11:56 +00:00
|
|
|
converter := converter != "" ? converter : A_AppData . "\..\Local\Pandoc\pandoc.exe"
|
2018-01-13 21:19:16 +00:00
|
|
|
_log.message("**createCheatSheet**: Variable set, source -> ``" . source . "``, the file does " . (FileExist(source) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**createCheatSheet**: Variable set, destDir -> ``" . destDir . "``, the file does " . (FileExist(destDir) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
_log.message("**createCheatSheet**: Variable set, converter -> ``" . converter . "``, the file does " . (FileExist(converter) ? "" : "**not** ") . "exist.", 5)
|
|
|
|
If (FileExist(source) && FileExist(destDir) && FileExist(converter)) {
|
|
|
|
FileRead, md, %source%
|
|
|
|
If (ErrorLevel = 0) {
|
2019-04-07 19:11:56 +00:00
|
|
|
_log.message("**createCheatSheet**: Converting source ``" . source . "`` to destination ``" . destDir . "\" . filename . ".md``.", 5)
|
2018-01-15 16:42:55 +00:00
|
|
|
md := RegExReplace(md, "s)^## Default hotkeys\R\R.+\R\### Window management", "## " . M_NAME . " " . M_VERSION . " default hotkeys`r`n`r`n### Window management")
|
2018-01-13 21:19:16 +00:00
|
|
|
md := StrReplace(md, "`r`n-------------------------------------------------------------------------------`r`n", "`r`n")
|
|
|
|
md := RegExReplace(md, "s)\R>.+?\R\R", "`r`n")
|
|
|
|
md := RegExReplace(md, "s)\R>.+?\R\R", "`r`n")
|
|
|
|
md := StrReplace(md, "``Config_hotkey=", "#### <kbd>")
|
|
|
|
md := RegExReplace(md, "::.+\R", "</kbd>")
|
|
|
|
md := StrReplace(md, "<kbd>#", "<kbd>Win</kbd><kbd>")
|
|
|
|
md := StrReplace(md, "<kbd>!", "<kbd>Alt</kbd><kbd>")
|
|
|
|
md := StrReplace(md, "<kbd>^", "<kbd>Ctrl</kbd><kbd>")
|
|
|
|
md := StrReplace(md, "<kbd>+", "<kbd>Shift</kbd><kbd>")
|
|
|
|
md := StrReplace(md, "<n>", "<n>")
|
|
|
|
FileDelete, %destDir%\%filename%.md
|
|
|
|
FileAppend, %md%, %destDir%\%filename%.md
|
|
|
|
}
|
2019-04-07 19:11:56 +00:00
|
|
|
_log.message("**createCheatSheet**: Running command ``" . converter . " -s -o " . destDir . "\" . filename . ".html --section-divs -c reset.css -c cheat_sheet.css " . destDir . "\" . filename . ".md``", 5)
|
|
|
|
RunWait, % converter . " -s -o " . destDir . "\" . filename . ".html --section-divs -c reset.css -c cheat_sheet.css " . destDir . "\" . filename . ".md"
|
2018-01-13 21:19:16 +00:00
|
|
|
}
|
|
|
|
_log.message("Creating the cheat sheet finished.", 4)
|
2019-04-07 19:11:56 +00:00
|
|
|
If (!FileExist(destDir . "\" . filename . ".html")) {
|
|
|
|
_log.message("**createCheatSheet**: Resulting file ``" . destDir . "\" . filename . ".html`` does not exist.", 2)
|
|
|
|
}
|
2018-01-13 21:19:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 14:43:12 +00:00
|
|
|
IntMin(int_1, int_2) {
|
|
|
|
Return, int_1 < int_2 ? int_1 : int_2
|
|
|
|
}
|
|
|
|
|
|
|
|
IntMax(int_1, int_2) {
|
|
|
|
Return, int_1 > int_2 ? int_1 : int_2
|
|
|
|
}
|
|
|
|
|
|
|
|
StrPad(s, chars, count) {
|
|
|
|
str := ""
|
|
|
|
Loop, % Abs(count)
|
|
|
|
str .= chars
|
|
|
|
If (count < 0)
|
|
|
|
Return SubStr(str . s, count + 1)
|
|
|
|
Else
|
|
|
|
Return SubStr(s . str, 1, count)
|
|
|
|
}
|