From 4375c518e43936506b29759c67f3e456c35af463 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Thu, 11 Jan 2024 20:14:43 -0500 Subject: [PATCH] Replace all tabs with spaces for consistency --- .gitattributes | 10 +- .vscode/launch.json | 108 +++---- cspell.json | 376 ++++++++++++------------ pyrightconfig.json | 186 ++++++------ src/textual_paint/edit_colors.py | 28 +- src/textual_paint/terminal_wallpaper.sh | 122 ++++---- 6 files changed, 415 insertions(+), 415 deletions(-) diff --git a/.gitattributes b/.gitattributes index 8c89a0f..6e3574f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -25,13 +25,13 @@ *.dbproj merge=union # Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain +*.doc diff=astextplain +*.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.vscode/launch.json b/.vscode/launch.json index d2618cb..61e98f0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,63 +1,63 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Run Textual App", - "type": "python", - "request": "launch", - // TODO: is there a way to get this from the environment, i.e. to use - // the binary that `which textual` would return, - // or to use textual as "module" but still run the correct app? - // At least with a virtual environment, I can point to a location - // that should exist if you follow the readme instructions. - // Although the docs for "program" say "Absolute path to the program." - "program": ".venv/bin/textual", - "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --inspect-layout"], - "console": "integratedTerminal", - "justMyCode": false - }, - { - "name": "Open A File in App", - "type": "python", - "request": "launch", - // "program": "src.textual_paint.paint", - // "args": ["LICENSE.txt"], - "program": ".venv/bin/textual", - "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --inspect-layout LICENSE.txt"], - "console": "integratedTerminal", - "justMyCode": false - }, - { - "name": "Recode Samples", - "type": "python", - "request": "launch", - "program": "src.textual_paint.paint", - "args": ["--recode-samples"], - "console": "integratedTerminal", - "justMyCode": false - }, - { - "name": "Debug --restart-on-changes file matching", - "type": "python", - "request": "launch", - "program": ".venv/bin/textual", - "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --restart-on-changes"], - "console": "integratedTerminal", - "justMyCode": false - }, - { + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Run Textual App", + "type": "python", + "request": "launch", + // TODO: is there a way to get this from the environment, i.e. to use + // the binary that `which textual` would return, + // or to use textual as "module" but still run the correct app? + // At least with a virtual environment, I can point to a location + // that should exist if you follow the readme instructions. + // Although the docs for "program" say "Absolute path to the program." + "program": ".venv/bin/textual", + "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --inspect-layout"], + "console": "integratedTerminal", + "justMyCode": false + }, + { + "name": "Open A File in App", + "type": "python", + "request": "launch", + // "program": "src.textual_paint.paint", + // "args": ["LICENSE.txt"], + "program": ".venv/bin/textual", + "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --inspect-layout LICENSE.txt"], + "console": "integratedTerminal", + "justMyCode": false + }, + { + "name": "Recode Samples", + "type": "python", + "request": "launch", + "program": "src.textual_paint.paint", + "args": ["--recode-samples"], + "console": "integratedTerminal", + "justMyCode": false + }, + { + "name": "Debug --restart-on-changes file matching", + "type": "python", + "request": "launch", + "program": ".venv/bin/textual", + "args": ["run", "--dev", "src.textual_paint.paint --clear-screen --restart-on-changes"], + "console": "integratedTerminal", + "justMyCode": false + }, + { "name": "Debug Tests", "type": "python", "request": "launch", - "program": ".venv/bin/pytest", - // "args": ["tests/test_snapshots.py::test_paint_open_dialog"], + "program": ".venv/bin/pytest", + // "args": ["tests/test_snapshots.py::test_paint_open_dialog"], "console": "integratedTerminal", "justMyCode": false, - // If using pytest-cov in the future: + // If using pytest-cov in the future: // "env": {"PYTEST_ADDOPTS": "--no-cov"} } - ] + ] } \ No newline at end of file diff --git a/cspell.json b/cspell.json index 7877032..0e3d391 100644 --- a/cspell.json +++ b/cspell.json @@ -1,190 +1,190 @@ { - "files": [ - "**", - ".*/**" - ], - "enableFiletypes": [ - "pip-requirements", - "shellscript", - "tlaplus_cfg", // file type detected wrong, I'm just trying to match *.cfg - "toml" - ], - "ignorePaths": [ - "snapshot_report.html", - "*.ambr", - ".git", - "*.(bmp|png|jpg|jpeg|gif|svg|ico|tiff|tif|ans|flf)", - "*.log", - "**/localization/*/**/*", - "**/localization/*.sh", - "**/typings/**/*", - "**/samples/*", - "**/samples/**/*", - "__pycache__", - "**/*.egg-info/**/*" - ], - "words": [ - "afterstep", - "ambr", - "Andale", - "APNG", - "appcode", - "appscript", - "asyncio", - "bezier", - "blackbox", - "Bresenham", - "Bresenham's", - "bsetbg", - "bucketization", - "Caja", - "Cascadia", - "clion", - "cmdpxl", - "COLORTERM", - "conhost", - "Consola", - "Consolas", - "Cour", - "dasharray", - "dcop", - "Deutsch", - "DIALOGEX", - "disambiguates", - "dockable", - "docstrings", - "domtree", - "Dunder", - "emacsclient", - "executablepath", - "fbsetbg", - "Figlet", - "Fira", - "fluxbox", - "fudgedness", - "gconftool", - "getbands", - "getpid", - "getpixel", - "goland", - "gsettings", - "gvim", - "hackily", - "Haha", - "hkey", - "hslrgb", - "hsrgb", - "humbnail", - "icewm", - "icewmbg", - "icns", - "Inconsolata", - "Inkscape", - "Intelli", - "kdesktop", - "ksmserver", - "kubuntu", - "linewrap", - "𝗟𝙇", - "llpaper", - "lrgb", - "lubuntu", - "Lubuntu", - "Lucida", - "lxde", - "LXDE", - "mateconftool", - "Menlo", - "mirc", - "modd", - "mspaint", - "mvim", - "mypy", - "myusername", - "Nemo", - "Noto", - "Odhner", - "openbox", - "Openbox", - "osascript", - "pacman", - "pagedown", - "pageup", - "palettized", - "pcmanfm", - "performantly", - "phpstorm", - "pipreqs", - "pipx", - "Playscii", - "polyline", - "psutil", - "pybabel", - "pycache", - "pyfakefs", - "pyfiglet", - "Pylance", - "pyobjc", - "pyperclip", - "pypixelart", - "pyright", - "pytest", - "pyxdg", - "qualname", - "rasterization", - "razorkwin", - "rects", - "renderable", - "rmam", - "rmate", - "rubymine", - "screeninfo", - "scrollbars", - "sdist", - "SETDESKWALLPAPER", - "setterm", - "setuptools", - "Shft", - "sixel", - "skeuomorphism", - "skool", - "smam", - "Smushing", - "stransi", - "STRINGTABLE", - "strxfrm", - "subl", - "tasklist", - "testpypi", - "textconv", - "thumbnailer", - "Thunar", - "tkinter", - "tlaplus", - "tput", - "truecolor", - "tspan", - "tspans", - "txtpnt", - "ubuntustudio", - "ufeff", - "undecorate", - "undoable", - "undos", - "ustom", - "venv", - "vkey", - "webp", - "webstorm", - "windowmaker", - "wmaker", - "wmsetbg", - "wstorm", - "xfce", - "xfconf", - "xfdesktop", - "xgettext", - "xpot", - "xubuntu" - ] + "files": [ + "**", + ".*/**" + ], + "enableFiletypes": [ + "pip-requirements", + "shellscript", + "tlaplus_cfg", // file type detected wrong, I'm just trying to match *.cfg + "toml" + ], + "ignorePaths": [ + "snapshot_report.html", + "*.ambr", + ".git", + "*.(bmp|png|jpg|jpeg|gif|svg|ico|tiff|tif|ans|flf)", + "*.log", + "**/localization/*/**/*", + "**/localization/*.sh", + "**/typings/**/*", + "**/samples/*", + "**/samples/**/*", + "__pycache__", + "**/*.egg-info/**/*" + ], + "words": [ + "afterstep", + "ambr", + "Andale", + "APNG", + "appcode", + "appscript", + "asyncio", + "bezier", + "blackbox", + "Bresenham", + "Bresenham's", + "bsetbg", + "bucketization", + "Caja", + "Cascadia", + "clion", + "cmdpxl", + "COLORTERM", + "conhost", + "Consola", + "Consolas", + "Cour", + "dasharray", + "dcop", + "Deutsch", + "DIALOGEX", + "disambiguates", + "dockable", + "docstrings", + "domtree", + "Dunder", + "emacsclient", + "executablepath", + "fbsetbg", + "Figlet", + "Fira", + "fluxbox", + "fudgedness", + "gconftool", + "getbands", + "getpid", + "getpixel", + "goland", + "gsettings", + "gvim", + "hackily", + "Haha", + "hkey", + "hslrgb", + "hsrgb", + "humbnail", + "icewm", + "icewmbg", + "icns", + "Inconsolata", + "Inkscape", + "Intelli", + "kdesktop", + "ksmserver", + "kubuntu", + "linewrap", + "𝗟𝙇", + "llpaper", + "lrgb", + "lubuntu", + "Lubuntu", + "Lucida", + "lxde", + "LXDE", + "mateconftool", + "Menlo", + "mirc", + "modd", + "mspaint", + "mvim", + "mypy", + "myusername", + "Nemo", + "Noto", + "Odhner", + "openbox", + "Openbox", + "osascript", + "pacman", + "pagedown", + "pageup", + "palettized", + "pcmanfm", + "performantly", + "phpstorm", + "pipreqs", + "pipx", + "Playscii", + "polyline", + "psutil", + "pybabel", + "pycache", + "pyfakefs", + "pyfiglet", + "Pylance", + "pyobjc", + "pyperclip", + "pypixelart", + "pyright", + "pytest", + "pyxdg", + "qualname", + "rasterization", + "razorkwin", + "rects", + "renderable", + "rmam", + "rmate", + "rubymine", + "screeninfo", + "scrollbars", + "sdist", + "SETDESKWALLPAPER", + "setterm", + "setuptools", + "Shft", + "sixel", + "skeuomorphism", + "skool", + "smam", + "Smushing", + "stransi", + "STRINGTABLE", + "strxfrm", + "subl", + "tasklist", + "testpypi", + "textconv", + "thumbnailer", + "Thunar", + "tkinter", + "tlaplus", + "tput", + "truecolor", + "tspan", + "tspans", + "txtpnt", + "ubuntustudio", + "ufeff", + "undecorate", + "undoable", + "undos", + "ustom", + "venv", + "vkey", + "webp", + "webstorm", + "windowmaker", + "wmaker", + "wmsetbg", + "wstorm", + "xfce", + "xfconf", + "xfdesktop", + "xgettext", + "xpot", + "xubuntu" + ] } diff --git a/pyrightconfig.json b/pyrightconfig.json index 45f3969..9a464eb 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,97 +1,97 @@ { - "include": [ - "**/*.py", - ], - "exclude": [ - "**/node_modules", - "**/__pycache__", - "**/build", - "**/.*" - ], - "strict": [ - // "**/*.py" - ], + "include": [ + "**/*.py", + ], + "exclude": [ + "**/node_modules", + "**/__pycache__", + "**/build", + "**/.*" + ], + "strict": [ + // "**/*.py" + ], - // CUSTOMIZATIONS - "reportOptionalMemberAccess": "warning", - // reportUnknownMemberType caused numerous bogus errors, - // with Textual's generic App[ResultType] and Screen[ScreenResultType] classes. - "reportUnknownMemberType": false, - "reportUnnecessaryTypeIgnoreComment": "information", + // CUSTOMIZATIONS + "reportOptionalMemberAccess": "warning", + // reportUnknownMemberType caused numerous bogus errors, + // with Textual's generic App[ResultType] and Screen[ScreenResultType] classes. + "reportUnknownMemberType": false, + "reportUnnecessaryTypeIgnoreComment": "information", - // STRICT PROFILE - // As far as I know, there's no way to inherit from strict and then loosen any rules, - // so I've copied from the table and am commenting out the ones I want to change. - // https://github.com/microsoft/pyright/blob/2a096860c11dff7bbda92f92efb0216e2580c2c6/docs/configuration.md#diagnostic-rule-defaults - // > In strict type checking mode, overrides may only increase the severity level (e.g. from "warning" to "error"). - "strictListInference": true, - "strictDictionaryInference": true, - "strictSetInference": true, - "analyzeUnannotatedFunctions": true, - "strictParameterNoneValue": true, - "enableTypeIgnoreComments": true, - "reportMissingModuleSource": "warning", - "reportMissingImports": "error", - "reportUndefinedVariable": "error", - "reportAssertAlwaysTrue": "error", - "reportInvalidStringEscapeSequence": "error", - "reportInvalidTypeVarUse": "error", - "reportMissingTypeStubs": "error", - "reportSelfClsParameterName": "error", - "reportUnsupportedDunderAll": "error", - "reportUnusedExpression": "error", - "reportWildcardImportFromLibrary": "error", - "reportGeneralTypeIssues": "error", - "reportOptionalSubscript": "error", - // "reportOptionalMemberAccess": "error", - "reportOptionalCall": "error", - "reportOptionalIterable": "error", - "reportOptionalContextManager": "error", - "reportOptionalOperand": "error", - "reportTypedDictNotRequiredAccess": "error", - "reportPrivateImportUsage": "error", - "reportUnboundVariable": "error", - "reportUnusedCoroutine": "error", - "reportConstantRedefinition": "error", - "reportDeprecated": "error", - "reportDuplicateImport": "error", - "reportFunctionMemberAccess": "error", - "reportIncompatibleMethodOverride": "error", - "reportIncompatibleVariableOverride": "error", - "reportIncompleteStub": "error", - "reportInconsistentConstructor": "error", - "reportInvalidStubStatement": "error", - "reportMatchNotExhaustive": "error", - "reportMissingParameterType": "error", - "reportMissingTypeArgument": "error", - "reportOverlappingOverload": "error", - "reportPrivateUsage": "error", - "reportTypeCommentUsage": "error", - "reportUnknownArgumentType": "error", - "reportUnknownLambdaType": "error", - // "reportUnknownMemberType": "error", - "reportUnknownParameterType": "error", - "reportUnknownVariableType": "error", - "reportUnnecessaryCast": "error", - "reportUnnecessaryComparison": "error", - "reportUnnecessaryContains": "error", - "reportUnnecessaryIsInstance": "error", - "reportUnusedClass": "error", - "reportUnusedImport": "error", - "reportUnusedFunction": "error", - "reportUnusedVariable": "error", - "reportUntypedBaseClass": "error", - "reportUntypedClassDecorator": "error", - "reportUntypedFunctionDecorator": "error", - "reportUntypedNamedTuple": "error", - "reportCallInDefaultInitializer": "none", - "reportImplicitOverride": "none", - "reportImplicitStringConcatenation": "none", - "reportImportCycles": "none", - "reportMissingSuperCall": "none", - "reportPropertyTypeMismatch": "none", - "reportShadowedImports": "none", - "reportUninitializedInstanceVariable": "none", - // "reportUnnecessaryTypeIgnoreComment": "none", - "reportUnusedCallResult": "none", + // STRICT PROFILE + // As far as I know, there's no way to inherit from strict and then loosen any rules, + // so I've copied from the table and am commenting out the ones I want to change. + // https://github.com/microsoft/pyright/blob/2a096860c11dff7bbda92f92efb0216e2580c2c6/docs/configuration.md#diagnostic-rule-defaults + // > In strict type checking mode, overrides may only increase the severity level (e.g. from "warning" to "error"). + "strictListInference": true, + "strictDictionaryInference": true, + "strictSetInference": true, + "analyzeUnannotatedFunctions": true, + "strictParameterNoneValue": true, + "enableTypeIgnoreComments": true, + "reportMissingModuleSource": "warning", + "reportMissingImports": "error", + "reportUndefinedVariable": "error", + "reportAssertAlwaysTrue": "error", + "reportInvalidStringEscapeSequence": "error", + "reportInvalidTypeVarUse": "error", + "reportMissingTypeStubs": "error", + "reportSelfClsParameterName": "error", + "reportUnsupportedDunderAll": "error", + "reportUnusedExpression": "error", + "reportWildcardImportFromLibrary": "error", + "reportGeneralTypeIssues": "error", + "reportOptionalSubscript": "error", + // "reportOptionalMemberAccess": "error", + "reportOptionalCall": "error", + "reportOptionalIterable": "error", + "reportOptionalContextManager": "error", + "reportOptionalOperand": "error", + "reportTypedDictNotRequiredAccess": "error", + "reportPrivateImportUsage": "error", + "reportUnboundVariable": "error", + "reportUnusedCoroutine": "error", + "reportConstantRedefinition": "error", + "reportDeprecated": "error", + "reportDuplicateImport": "error", + "reportFunctionMemberAccess": "error", + "reportIncompatibleMethodOverride": "error", + "reportIncompatibleVariableOverride": "error", + "reportIncompleteStub": "error", + "reportInconsistentConstructor": "error", + "reportInvalidStubStatement": "error", + "reportMatchNotExhaustive": "error", + "reportMissingParameterType": "error", + "reportMissingTypeArgument": "error", + "reportOverlappingOverload": "error", + "reportPrivateUsage": "error", + "reportTypeCommentUsage": "error", + "reportUnknownArgumentType": "error", + "reportUnknownLambdaType": "error", + // "reportUnknownMemberType": "error", + "reportUnknownParameterType": "error", + "reportUnknownVariableType": "error", + "reportUnnecessaryCast": "error", + "reportUnnecessaryComparison": "error", + "reportUnnecessaryContains": "error", + "reportUnnecessaryIsInstance": "error", + "reportUnusedClass": "error", + "reportUnusedImport": "error", + "reportUnusedFunction": "error", + "reportUnusedVariable": "error", + "reportUntypedBaseClass": "error", + "reportUntypedClassDecorator": "error", + "reportUntypedFunctionDecorator": "error", + "reportUntypedNamedTuple": "error", + "reportCallInDefaultInitializer": "none", + "reportImplicitOverride": "none", + "reportImplicitStringConcatenation": "none", + "reportImportCycles": "none", + "reportMissingSuperCall": "none", + "reportPropertyTypeMismatch": "none", + "reportShadowedImports": "none", + "reportUninitializedInstanceVariable": "none", + // "reportUnnecessaryTypeIgnoreComment": "none", + "reportUnusedCallResult": "none", } \ No newline at end of file diff --git a/src/textual_paint/edit_colors.py b/src/textual_paint/edit_colors.py index e6b2948..51d59bd 100644 --- a/src/textual_paint/edit_colors.py +++ b/src/textual_paint/edit_colors.py @@ -22,25 +22,25 @@ from textual_paint.windows import DialogWindow # https://github.com/kouzhudong/win2k/blob/ce6323f76d5cd7d136b74427dad8f94ee4c389d2/trunk/private/shell/win16/comdlg/color.c#L38-L43 # These are a fallback in case colors are not received from some driver. # const default_basic_colors = [ -# "#8080FF", "#80FFFF", "#80FF80", "#80FF00", "#FFFF80", "#FF8000", "#C080FF", "#FF80FF", -# "#0000FF", "#00FFFF", "#00FF80", "#40FF00", "#FFFF00", "#C08000", "#C08080", "#FF00FF", -# "#404080", "#4080FF", "#00FF00", "#808000", "#804000", "#FF8080", "#400080", "#8000FF", -# "#000080", "#0080FF", "#008000", "#408000", "#FF0000", "#A00000", "#800080", "#FF0080", -# "#000040", "#004080", "#004000", "#404000", "#800000", "#400000", "#400040", "#800040", -# "#000000", "#008080", "#408080", "#808080", "#808040", "#C0C0C0", "#400040", "#FFFFFF", +# "#8080FF", "#80FFFF", "#80FF80", "#80FF00", "#FFFF80", "#FF8000", "#C080FF", "#FF80FF", +# "#0000FF", "#00FFFF", "#00FF80", "#40FF00", "#FFFF00", "#C08000", "#C08080", "#FF00FF", +# "#404080", "#4080FF", "#00FF00", "#808000", "#804000", "#FF8080", "#400080", "#8000FF", +# "#000080", "#0080FF", "#008000", "#408000", "#FF0000", "#A00000", "#800080", "#FF0080", +# "#000040", "#004080", "#004000", "#404000", "#800000", "#400000", "#400040", "#800040", +# "#000000", "#008080", "#408080", "#808080", "#808040", "#C0C0C0", "#400040", "#FFFFFF", # ]; # Grabbed with Color Cop from the screen with Windows 98 SE running in VMWare basic_colors = [ - "#FF8080", "#FFFF80", "#80FF80", "#00FF80", "#80FFFF", "#0080FF", "#FF80C0", "#FF80FF", - "#FF0000", "#FFFF00", "#80FF00", "#00FF40", "#00FFFF", "#0080C0", "#8080C0", "#FF00FF", - "#804040", "#FF8040", "#00FF00", "#008080", "#004080", "#8080FF", "#800040", "#FF0080", - "#800000", "#FF8000", "#008000", "#008040", "#0000FF", "#0000A0", "#800080", "#8000FF", - "#400000", "#804000", "#004000", "#004040", "#000080", "#000040", "#400040", "#400080", - "#000000", "#808000", "#808040", "#808080", "#408080", "#C0C0C0", "#400040", "#FFFFFF", + "#FF8080", "#FFFF80", "#80FF80", "#00FF80", "#80FFFF", "#0080FF", "#FF80C0", "#FF80FF", + "#FF0000", "#FFFF00", "#80FF00", "#00FF40", "#00FFFF", "#0080C0", "#8080C0", "#FF00FF", + "#804040", "#FF8040", "#00FF00", "#008080", "#004080", "#8080FF", "#800040", "#FF0080", + "#800000", "#FF8000", "#008000", "#008040", "#0000FF", "#0000A0", "#800080", "#8000FF", + "#400000", "#804000", "#004000", "#004040", "#000080", "#000040", "#400040", "#400080", + "#000000", "#808000", "#808040", "#808080", "#408080", "#C0C0C0", "#400040", "#FFFFFF", ] custom_colors = [ - "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", - "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", + "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", + "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", ] num_colors_per_row = 8 diff --git a/src/textual_paint/terminal_wallpaper.sh b/src/textual_paint/terminal_wallpaper.sh index 30c211b..4473230 100644 --- a/src/textual_paint/terminal_wallpaper.sh +++ b/src/textual_paint/terminal_wallpaper.sh @@ -6,7 +6,7 @@ tput clear # Check environment variables init_script="$HOME/.bashrc" if [[ -f $HOME/.zshrc ]]; then - init_script="$HOME/.zshrc" + init_script="$HOME/.zshrc" fi # uninstall_instruction="uninstall terminal wallpaper support with 'textual-paint --remove-wallpaper'" this_script_abs_path=${BASH_SOURCE[0]} @@ -15,80 +15,80 @@ source_line="source $this_script_abs_path" uninstall_instruction="uninstall terminal wallpaper support by removing \"$source_line\" from $init_script" add_var_instruction="Add it to $init_script before the line that includes terminal_wallpaper.sh (\"$source_line\"), or $uninstall_instruction" if [[ -z $TERMINAL_WALLPAPER ]]; then - echo "TERMINAL_WALLPAPER not set. $add_var_instruction" - return + echo "TERMINAL_WALLPAPER not set. $add_var_instruction" + return fi if [[ -z $TERMINAL_WALLPAPER_MODE ]]; then - echo "TERMINAL_WALLPAPER_MODE not set. $add_var_instruction" - return + echo "TERMINAL_WALLPAPER_MODE not set. $add_var_instruction" + return fi # Check file exists if [[ ! -f $TERMINAL_WALLPAPER ]]; then - echo "TERMINAL_WALLPAPER file not found: $TERMINAL_WALLPAPER\nUpdate TERMINAL_WALLPAPER in $init_script, or $uninstall_instruction" - return + echo "TERMINAL_WALLPAPER file not found: $TERMINAL_WALLPAPER\nUpdate TERMINAL_WALLPAPER in $init_script, or $uninstall_instruction" + return fi # Draw terminal background according to mode if [[ $TERMINAL_WALLPAPER_MODE == "TOP_LEFT" || $TERMINAL_WALLPAPER_MODE == "TOP-LEFT" ]]; then - cat $TERMINAL_WALLPAPER + cat $TERMINAL_WALLPAPER else - # Split lines of terminal background into array - IFS=$'\n' read -d '' -r -a lines < $TERMINAL_WALLPAPER + # Split lines of terminal background into array + IFS=$'\n' read -d '' -r -a lines < $TERMINAL_WALLPAPER - # Measure image size - image_height=${#lines[@]} - image_width=0 - for (( y=0; y<$image_height; y++ )); do - line=${lines[$y]} - # Have to strip ANSI escape sequences from line length - line_length=${#line} - filtered_line=$(sed -r "s/\x1B\[[0-9;]*[mK]//g" <<< "$line") - line_width=${#filtered_line} + # Measure image size + image_height=${#lines[@]} + image_width=0 + for (( y=0; y<$image_height; y++ )); do + line=${lines[$y]} + # Have to strip ANSI escape sequences from line length + line_length=${#line} + filtered_line=$(sed -r "s/\x1B\[[0-9;]*[mK]//g" <<< "$line") + line_width=${#filtered_line} - # echo "y=$y line : $line line_length=$line_length" - # echo "y=$y filtered line: $filtered_line line_width=$line_width" + # echo "y=$y line : $line line_length=$line_length" + # echo "y=$y filtered line: $filtered_line line_width=$line_width" - if [[ $line_width -gt $image_width ]]; then - image_width=$line_width - fi - done + if [[ $line_width -gt $image_width ]]; then + image_width=$line_width + fi + done - if [[ $TERMINAL_WALLPAPER_MODE == "CENTER" || $TERMINAL_WALLPAPER_MODE == "CENTERED" ]]; then - # Calculate offset - terminal_width=$(tput cols) - terminal_height=$(tput lines) - offset_x=$(( ($terminal_width - $image_width) / 2 )) - offset_y=$(( ($terminal_height - $image_height) / 2 )) - # Ensure offset is positive - if [[ $offset_x -lt 0 ]]; then offset_x=0; fi - if [[ $offset_y -lt 0 ]]; then offset_y=0; fi - # Draw image - for (( i=0; i<$image_height; i++ )); do - tput cup $(( $offset_y + $i )) $offset_x - echo -e "${lines[$i]}" - done - elif [[ $TERMINAL_WALLPAPER_MODE == "TILE" || $TERMINAL_WALLPAPER_MODE == "TILED" ]]; then - # Draw tiled image - tput rmam - setterm -linewrap off - terminal_width=$(tput cols) - terminal_height=$(tput lines) - for (( y=0; y<$terminal_height; y+=$image_height )); do - for (( x=0; x<$terminal_width; x+=$image_width )); do - for (( i=0; i<$image_height; i++ )); do - # Don't scroll past bottom of terminal - if [[ $(( $y + $i + 1 )) -ge $terminal_height ]]; then - break - fi - # Draw line - tput cup $(( $y + $i )) $x - echo -e "${lines[$i]}" - done - done - done - tput smam - setterm -linewrap on - fi + if [[ $TERMINAL_WALLPAPER_MODE == "CENTER" || $TERMINAL_WALLPAPER_MODE == "CENTERED" ]]; then + # Calculate offset + terminal_width=$(tput cols) + terminal_height=$(tput lines) + offset_x=$(( ($terminal_width - $image_width) / 2 )) + offset_y=$(( ($terminal_height - $image_height) / 2 )) + # Ensure offset is positive + if [[ $offset_x -lt 0 ]]; then offset_x=0; fi + if [[ $offset_y -lt 0 ]]; then offset_y=0; fi + # Draw image + for (( i=0; i<$image_height; i++ )); do + tput cup $(( $offset_y + $i )) $offset_x + echo -e "${lines[$i]}" + done + elif [[ $TERMINAL_WALLPAPER_MODE == "TILE" || $TERMINAL_WALLPAPER_MODE == "TILED" ]]; then + # Draw tiled image + tput rmam + setterm -linewrap off + terminal_width=$(tput cols) + terminal_height=$(tput lines) + for (( y=0; y<$terminal_height; y+=$image_height )); do + for (( x=0; x<$terminal_width; x+=$image_width )); do + for (( i=0; i<$image_height; i++ )); do + # Don't scroll past bottom of terminal + if [[ $(( $y + $i + 1 )) -ge $terminal_height ]]; then + break + fi + # Draw line + tput cup $(( $y + $i )) $x + echo -e "${lines[$i]}" + done + done + done + tput smam + setterm -linewrap on + fi fi # Reset cursor position