added log and lib (part)

This commit is contained in:
joten 2016-02-12 20:11:03 +01:00
parent 5982f0e209
commit 70d79b7987
4 changed files with 87 additions and 1 deletions

28
src/Lib.ahk Normal file
View file

@ -0,0 +1,28 @@
/*
:title: bug.n -- Tiling Window Management
:copyright: (c) 2016 by Joshua Fuhs & joten <https://github.com/fuhsjr00/bug.n>
:license: GNU General Public License version 3;
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.
*/
Int_min(a, b) {
Return, a < b ? a : b
}
Int_max(a, b) {
Return, a > b ? a : b
}
Str_pad(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)
}

53
src/Log.ahk Normal file
View file

@ -0,0 +1,53 @@
/*
:title: bug.n -- Tiling Window Management
:copyright: (c) 2016 by Joshua Fuhs & joten <https://github.com/fuhsjr00/bug.n>
:license: GNU General Public License version 3;
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.
*/
Log_init(truncate = True) {
Global Log_file, Log_level
Global Log_level_#0, Log_level_#1, Log_level_#2, Log_level_#3, Log_level_#4, Log_level_#5, Log_level_#6, Log_level_#7
If Not Log_level
Log_level := 2
l := ";CRITICAL;ERROR;WARNING;INFO;DEBUG;SUPER"
StringSplit, Log_level_#, l, `;
If truncate And FileExist(Log_file)
FileDelete, %Log_file%
FormatTime, t, , yyyy-MM-dd
FileAppend, % "`r`n# " . t . "`r`n", %Log_file%
Log_msg("Log started", 4)
}
Log_msg(text, l, t = True) { ;; level = 0: log in any case
Global Log_file, Log_level
Global Log_level_#1, Log_level_#2, Log_level_#3, Log_level_#4, Log_level_#5, Log_level_#6, Log_level_#7
If (Log_level >= l) {
If t
FormatTime, t, , yyyy-MM-dd HH:mm:ss
i := l + 1
text := Str_pad(t, " ", 19) . "> " . Str_pad(Log_level_#%i%, ".", 8) . ": " . text . "`r`n"
FileAppend, %text%, %Log_file%
}
}
Log_setLevel(d, l = 0) {
Global Log_level
Global Log_level_#1, Log_level_#2, Log_level_#3, Log_level_#4, Log_level_#5, Log_level_#6, Log_level_#7
l := l ? l : Log_level
l := Int_min(Int_max(l + d, 1), 6)
If (l != Log_level) {
Log_level := l
i := l + 1
Log_msg("Log level set to " . Log_level_#%i%, 0)
}
}

View file

@ -26,12 +26,14 @@ SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;; Pseudo main function
Main_appDir := ""
Log_level := ""
If 0 = 1
Main_appDir = %1%
Main_setup()
Debug_initLog(Main_logFile, 0, False)
Log_init()
Debug_logMessage("====== Initializing ======", 0)
Config_filePath := Main_appDir "\Config.ini"
@ -165,6 +167,7 @@ Main_setup() {
If (Main_appDir = "")
Main_appDir := winAppDir . "\bug.n"
Main_logFile := Main_appDir . "\log.txt"
Log_file := Main_appDir . "\log.md"
Main_dataDir := Main_appDir . "\data"
Main_autoLayout := Main_dataDir . "\_Layout.ini"
Main_autoWindowState := Main_dataDir . "\_WindowState.ini"
@ -180,6 +183,8 @@ Return
#Include Bar.ahk
#Include Config.ahk
#Include Debug.ahk
#Include Lib.ahk
#Include Log.ahk
#Include Manager.ahk
#Include Monitor.ahk
#Include ResourceMonitor.ahk

View file

@ -240,7 +240,7 @@ Window_move(wndId, x, y, width, height) {
Local wndMinMax, WM_ENTERSIZEMOVE, WM_EXITSIZEMOVE
Local wndH, wndW, wndX, wndY
If Not wndId Window_getPosEx(wndId, wndX, wndY, wndW, wndH) And (Abs(wndX - x) < 2 And Abs(wndY - y) < 2 And Abs(wndW - width) < 2 And Abs(wndH - height) < 2)
If Not wndId Or Window_getPosEx(wndId, wndX, wndY, wndW, wndH) And (Abs(wndX - x) < 2 And Abs(wndY - y) < 2 And Abs(wndW - width) < 2 And Abs(wndH - height) < 2)
Return, 0
If Window_isHung(wndId) {