Fixed clang-format; updated cmakelists
parent
39fd726a51
commit
8d792bbc50
150
.clang-format
150
.clang-format
|
@ -1 +1,149 @@
|
||||||
IndentWidth: 4
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveMacros: true
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
|
AlignConsecutiveBitFields: true
|
||||||
|
AlignConsecutiveDeclarations: true
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 79
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentWidth: 4
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
Standard: Latest
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 4
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- STRINGIZE
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
...
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
make format
|
|
@ -1,5 +1,5 @@
|
||||||
# Upcoming
|
# Upcoming
|
||||||
## v0.1
|
## v1.0
|
||||||
* Switched build to CMake
|
* Switched build to CMake
|
||||||
* Completely overhauled code structure
|
* Completely overhauled code structure
|
||||||
* Separate code into logical blocks
|
* Separate code into logical blocks
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
* Add a desktop entry when installing
|
* Add a desktop entry when installing
|
||||||
based on [desktopentry](https://st.suckless.org/patches/desktopentry/)
|
based on [desktopentry](https://st.suckless.org/patches/desktopentry/)
|
||||||
|
|
||||||
## v0.2
|
## v1.1
|
||||||
* Configurable transparency (focused and unfocused)
|
* Configurable transparency (focused and unfocused)
|
||||||
based on [alpha](https://st.suckless.org/patches/alpha/) and
|
based on [alpha](https://st.suckless.org/patches/alpha/) and
|
||||||
[alpha focus highlight](https://st.suckless.org/patches/alpha_focus_highlight/)
|
[alpha focus highlight](https://st.suckless.org/patches/alpha_focus_highlight/)
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
* Copy to clipboard on selection
|
* Copy to clipboard on selection
|
||||||
based on [one clipboard](https://st.suckless.org/patches/clipboard/)
|
based on [one clipboard](https://st.suckless.org/patches/clipboard/)
|
||||||
|
|
||||||
## v0.3
|
## v1.2
|
||||||
* Add better/gapless rendering of lines/blocks
|
* Add better/gapless rendering of lines/blocks
|
||||||
based on [boxdraw](https://st.suckless.org/patches/boxdraw/)
|
based on [boxdraw](https://st.suckless.org/patches/boxdraw/)
|
||||||
* Add support for multiple fonts
|
* Add support for multiple fonts
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
* Hide cursor when working in the terminal
|
* Hide cursor when working in the terminal
|
||||||
based on [hidecursor](https://st.suckless.org/patches/hidecursor/)
|
based on [hidecursor](https://st.suckless.org/patches/hidecursor/)
|
||||||
|
|
||||||
## v0.4
|
## v2.0
|
||||||
* Add ligature support
|
* Add ligature support
|
||||||
based on [ligature support](https://st.suckless.org/patches/ligatures/)
|
based on [ligature support](https://st.suckless.org/patches/ligatures/)
|
||||||
* Support for multiple color pallets
|
* Support for multiple color pallets
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -10,6 +10,9 @@ PREFIX := /usr/local
|
||||||
MANPREFIX := $(PREFIX)/share/man
|
MANPREFIX := $(PREFIX)/share/man
|
||||||
|
|
||||||
|
|
||||||
|
SHELL := $(shell which sh)
|
||||||
|
|
||||||
|
|
||||||
all: debug
|
all: debug
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
|
||||||
|
@ -90,4 +93,4 @@ clean-debug:
|
||||||
|
|
||||||
# =====FORMAT CODE=====
|
# =====FORMAT CODE=====
|
||||||
format:
|
format:
|
||||||
@ clang-format -i --style=file src/**/*.c src/**/*.h
|
@ clang-format -i --style=file src/**/*.c src/**/*.h src/*.c src/*.h
|
||||||
|
|
|
@ -19,7 +19,7 @@ add_definitions(-DVERSION="${CMAKE_PROJECT_VERSION}" -D_XOPEN_SOURCE=600)
|
||||||
|
|
||||||
# =====BUILD TYPES=====
|
# =====BUILD TYPES=====
|
||||||
# Debug
|
# Debug
|
||||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -Wall -O0 -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0 -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -pedantic")
|
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -pedantic")
|
||||||
|
|
||||||
# Arch doesn't use static libraries
|
# Arch doesn't use static libraries
|
||||||
|
@ -43,8 +43,6 @@ add_executable(stj x.c "${st_SRC}" "${main_SRC}")
|
||||||
find_package(Freetype 2 REQUIRED)
|
find_package(Freetype 2 REQUIRED)
|
||||||
target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}")
|
target_include_directories(stj PRIVATE "${FREETYPE_INCLUDE_DIRS}")
|
||||||
target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}")
|
target_link_libraries(stj PRIVATE "${FREETYPE_LIBRARIES}")
|
||||||
target_link_libraries(stj PRIVATE Xft)
|
|
||||||
target_link_libraries(stj PRIVATE Xrender)
|
|
||||||
|
|
||||||
find_package(Fontconfig 2 REQUIRED)
|
find_package(Fontconfig 2 REQUIRED)
|
||||||
target_include_directories(stj PRIVATE "${Fontconfig_INCLUDE_DIRS}")
|
target_include_directories(stj PRIVATE "${Fontconfig_INCLUDE_DIRS}")
|
||||||
|
@ -53,6 +51,9 @@ target_link_libraries(stj PRIVATE "${Fontconfig_LIBRARIES}")
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED)
|
||||||
target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}")
|
target_include_directories(stj PRIVATE "${X11_INCLUDE_DIR}")
|
||||||
target_link_libraries(stj PRIVATE "${X11_LIBRARIES}")
|
target_link_libraries(stj PRIVATE "${X11_LIBRARIES}")
|
||||||
|
# TODO Find out if these are included in the above statement or not
|
||||||
|
# target_link_libraries(stj PRIVATE Xft)
|
||||||
|
# target_link_libraries(stj PRIVATE Xrender)
|
||||||
|
|
||||||
# Normally provided with clang
|
# Normally provided with clang
|
||||||
target_link_libraries(stj PRIVATE m)
|
target_link_libraries(stj PRIVATE m)
|
||||||
|
|
60
src/arg.h
60
src/arg.h
|
@ -9,40 +9,40 @@
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
|
|
||||||
/* use main(int argc, char *argv[]) */
|
/* use main(int argc, char *argv[]) */
|
||||||
#define ARGBEGIN \
|
#define ARGBEGIN \
|
||||||
for (argv0 = *argv, argv++, argc--; \
|
for (argv0 = *argv, argv++, argc--; \
|
||||||
argv[0] && argv[0][0] == '-' && argv[0][1]; argc--, argv++) { \
|
argv[0] && argv[0][0] == '-' && argv[0][1]; argc--, argv++) { \
|
||||||
char argc_; \
|
char argc_; \
|
||||||
char **argv_; \
|
char **argv_; \
|
||||||
int brk_; \
|
int brk_; \
|
||||||
if (argv[0][1] == '-' && argv[0][2] == '\0') { \
|
if (argv[0][1] == '-' && argv[0][2] == '\0') { \
|
||||||
argv++; \
|
argv++; \
|
||||||
argc--; \
|
argc--; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
int i_; \
|
int i_; \
|
||||||
for (i_ = 1, brk_ = 0, argv_ = argv; argv[0][i_] && !brk_; i_++) { \
|
for (i_ = 1, brk_ = 0, argv_ = argv; argv[0][i_] && !brk_; i_++) { \
|
||||||
if (argv_ != argv) \
|
if (argv_ != argv) \
|
||||||
break; \
|
break; \
|
||||||
argc_ = argv[0][i_]; \
|
argc_ = argv[0][i_]; \
|
||||||
switch (argc_)
|
switch (argc_)
|
||||||
|
|
||||||
#define ARGEND \
|
#define ARGEND \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ARGC() argc_
|
#define ARGC() argc_
|
||||||
|
|
||||||
#define EARGF(x) \
|
#define EARGF(x) \
|
||||||
((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \
|
((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \
|
||||||
? ((x), abort(), (char *)0) \
|
? ((x), abort(), (char *)0) \
|
||||||
: (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \
|
: (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \
|
||||||
: (argc--, argv++, argv[0])))
|
: (argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#define ARGF() \
|
#define ARGF() \
|
||||||
((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \
|
((argv[0][i_ + 1] == '\0' && argv[1] == NULL) \
|
||||||
? (char *)0 \
|
? (char *)0 \
|
||||||
: (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \
|
: (brk_ = 1, (argv[0][i_ + 1] != '\0') ? (&argv[0][i_ + 1]) \
|
||||||
: (argc--, argv++, argv[0])))
|
: (argc--, argv++, argv[0])))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
*
|
*
|
||||||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
||||||
*/
|
*/
|
||||||
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
|
static char *font =
|
||||||
|
"Liberation Mono:pixelsize=12:antialias=true:autohint=true";
|
||||||
static int borderpx = 2;
|
static int borderpx = 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -17,9 +18,9 @@ static int borderpx = 2;
|
||||||
* 5: value of shell in config.h
|
* 5: value of shell in config.h
|
||||||
*/
|
*/
|
||||||
static char *shell = "/bin/sh";
|
static char *shell = "/bin/sh";
|
||||||
char *utmp = NULL;
|
char * utmp = NULL;
|
||||||
/* scroll program: to enable use a string like "scroll" */
|
/* scroll program: to enable use a string like "scroll" */
|
||||||
char *scroll = NULL;
|
char *scroll = NULL;
|
||||||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
||||||
|
|
||||||
/* identification sequence returned in DA and DECID */
|
/* identification sequence returned in DA and DECID */
|
||||||
|
@ -126,9 +127,9 @@ static const char *colorname[] = {
|
||||||
* Default colors (colorname index)
|
* Default colors (colorname index)
|
||||||
* foreground, background, cursor, reverse cursor
|
* foreground, background, cursor, reverse cursor
|
||||||
*/
|
*/
|
||||||
unsigned int defaultfg = 7;
|
unsigned int defaultfg = 7;
|
||||||
unsigned int defaultbg = 0;
|
unsigned int defaultbg = 0;
|
||||||
static unsigned int defaultcs = 256;
|
static unsigned int defaultcs = 256;
|
||||||
static unsigned int defaultrcs = 257;
|
static unsigned int defaultrcs = 257;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -151,8 +152,8 @@ static unsigned int rows = 24;
|
||||||
* Default colour and shape of the mouse cursor
|
* Default colour and shape of the mouse cursor
|
||||||
*/
|
*/
|
||||||
static unsigned int mouseshape = XC_xterm;
|
static unsigned int mouseshape = XC_xterm;
|
||||||
static unsigned int mousefg = 7;
|
static unsigned int mousefg = 7;
|
||||||
static unsigned int mousebg = 0;
|
static unsigned int mousebg = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Color used to display font attributes when fontconfig selected a font which
|
* Color used to display font attributes when fontconfig selected a font which
|
||||||
|
@ -181,7 +182,7 @@ static MouseShortcut mshortcuts[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Internal keyboard shortcuts. */
|
/* Internal keyboard shortcuts. */
|
||||||
#define MODKEY Mod1Mask
|
#define MODKEY Mod1Mask
|
||||||
#define TERMMOD (ControlMask | ShiftMask)
|
#define TERMMOD (ControlMask | ShiftMask)
|
||||||
|
|
||||||
static Shortcut shortcuts[] = {
|
static Shortcut shortcuts[] = {
|
||||||
|
|
19
src/config.h
19
src/config.h
|
@ -5,7 +5,8 @@
|
||||||
*
|
*
|
||||||
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
|
||||||
*/
|
*/
|
||||||
static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
|
static char *font =
|
||||||
|
"Liberation Mono:pixelsize=12:antialias=true:autohint=true";
|
||||||
static int borderpx = 2;
|
static int borderpx = 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -17,9 +18,9 @@ static int borderpx = 2;
|
||||||
* 5: value of shell in config.h
|
* 5: value of shell in config.h
|
||||||
*/
|
*/
|
||||||
static char *shell = "/bin/sh";
|
static char *shell = "/bin/sh";
|
||||||
char *utmp = NULL;
|
char * utmp = NULL;
|
||||||
/* scroll program: to enable use a string like "scroll" */
|
/* scroll program: to enable use a string like "scroll" */
|
||||||
char *scroll = NULL;
|
char *scroll = NULL;
|
||||||
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
|
||||||
|
|
||||||
/* identification sequence returned in DA and DECID */
|
/* identification sequence returned in DA and DECID */
|
||||||
|
@ -126,9 +127,9 @@ static const char *colorname[] = {
|
||||||
* Default colors (colorname index)
|
* Default colors (colorname index)
|
||||||
* foreground, background, cursor, reverse cursor
|
* foreground, background, cursor, reverse cursor
|
||||||
*/
|
*/
|
||||||
unsigned int defaultfg = 7;
|
unsigned int defaultfg = 7;
|
||||||
unsigned int defaultbg = 0;
|
unsigned int defaultbg = 0;
|
||||||
static unsigned int defaultcs = 256;
|
static unsigned int defaultcs = 256;
|
||||||
static unsigned int defaultrcs = 257;
|
static unsigned int defaultrcs = 257;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -151,8 +152,8 @@ static unsigned int rows = 24;
|
||||||
* Default colour and shape of the mouse cursor
|
* Default colour and shape of the mouse cursor
|
||||||
*/
|
*/
|
||||||
static unsigned int mouseshape = XC_xterm;
|
static unsigned int mouseshape = XC_xterm;
|
||||||
static unsigned int mousefg = 7;
|
static unsigned int mousefg = 7;
|
||||||
static unsigned int mousebg = 0;
|
static unsigned int mousebg = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Color used to display font attributes when fontconfig selected a font which
|
* Color used to display font attributes when fontconfig selected a font which
|
||||||
|
@ -181,7 +182,7 @@ static MouseShortcut mshortcuts[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Internal keyboard shortcuts. */
|
/* Internal keyboard shortcuts. */
|
||||||
#define MODKEY Mod1Mask
|
#define MODKEY Mod1Mask
|
||||||
#define TERMMOD (ControlMask | ShiftMask)
|
#define TERMMOD (ControlMask | ShiftMask)
|
||||||
|
|
||||||
static Shortcut shortcuts[] = {
|
static Shortcut shortcuts[] = {
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#ifndef MACROS_H
|
#ifndef MACROS_H
|
||||||
#define MACROS_H
|
#define MACROS_H
|
||||||
|
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||||
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
#define LEN(a) (sizeof(a) / sizeof(a)[0])
|
||||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||||
#define DIVCEIL(n, d) (((n) + ((d)-1)) / (d))
|
#define DIVCEIL(n, d) (((n) + ((d)-1)) / (d))
|
||||||
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
|
||||||
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
|
#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
|
||||||
#define ATTRCMP(a, b) \
|
#define ATTRCMP(a, b) \
|
||||||
((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
|
((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
|
||||||
#define TIMEDIFF(t1, t2) \
|
#define TIMEDIFF(t1, t2) \
|
||||||
((t1.tv_sec - t2.tv_sec) * 1000 + (t1.tv_nsec - t2.tv_nsec) / 1E6)
|
((t1.tv_sec - t2.tv_sec) * 1000 + (t1.tv_nsec - t2.tv_nsec) / 1E6)
|
||||||
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
|
||||||
|
|
||||||
#define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
#define TRUECOLOR(r, g, b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
|
||||||
#define IS_TRUECOL(x) (1 << 24 & (x))
|
#define IS_TRUECOL(x) (1 << 24 & (x))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -43,8 +43,8 @@ void selscroll(int orig, int n) {
|
||||||
sel.ob.y += n;
|
sel.ob.y += n;
|
||||||
sel.oe.y += n;
|
sel.oe.y += n;
|
||||||
|
|
||||||
if (sel.ob.y < term.top || sel.ob.y > term.bot || sel.oe.y < term.top ||
|
if (sel.ob.y < term.top || sel.ob.y > term.bot ||
|
||||||
sel.oe.y > term.bot) {
|
sel.oe.y < term.top || sel.oe.y > term.bot) {
|
||||||
selclear();
|
selclear();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
372
src/st/st.c
372
src/st/st.c
|
@ -38,28 +38,28 @@
|
||||||
#define STR_ARG_SIZ ESC_ARG_SIZ
|
#define STR_ARG_SIZ ESC_ARG_SIZ
|
||||||
|
|
||||||
/* macros */
|
/* macros */
|
||||||
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
#define IS_SET(flag) ((term.mode & (flag)) != 0)
|
||||||
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == 0x7f)
|
#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == 0x7f)
|
||||||
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
|
||||||
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
|
||||||
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
|
||||||
|
|
||||||
enum term_mode {
|
enum term_mode {
|
||||||
MODE_WRAP = 1 << 0,
|
MODE_WRAP = 1 << 0,
|
||||||
MODE_INSERT = 1 << 1,
|
MODE_INSERT = 1 << 1,
|
||||||
MODE_ALTSCREEN = 1 << 2,
|
MODE_ALTSCREEN = 1 << 2,
|
||||||
MODE_CRLF = 1 << 3,
|
MODE_CRLF = 1 << 3,
|
||||||
MODE_ECHO = 1 << 4,
|
MODE_ECHO = 1 << 4,
|
||||||
MODE_PRINT = 1 << 5,
|
MODE_PRINT = 1 << 5,
|
||||||
MODE_UTF8 = 1 << 6,
|
MODE_UTF8 = 1 << 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum cursor_movement { CURSOR_SAVE, CURSOR_LOAD };
|
enum cursor_movement { CURSOR_SAVE, CURSOR_LOAD };
|
||||||
|
|
||||||
enum cursor_state {
|
enum cursor_state {
|
||||||
CURSOR_DEFAULT = 0,
|
CURSOR_DEFAULT = 0,
|
||||||
CURSOR_WRAPNEXT = 1,
|
CURSOR_WRAPNEXT = 1,
|
||||||
CURSOR_ORIGIN = 2
|
CURSOR_ORIGIN = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum charset {
|
enum charset {
|
||||||
|
@ -73,63 +73,63 @@ enum charset {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum escape_state {
|
enum escape_state {
|
||||||
ESC_START = 1,
|
ESC_START = 1,
|
||||||
ESC_CSI = 2,
|
ESC_CSI = 2,
|
||||||
ESC_STR = 4, /* DCS, OSC, PM, APC */
|
ESC_STR = 4, /* DCS, OSC, PM, APC */
|
||||||
ESC_ALTCHARSET = 8,
|
ESC_ALTCHARSET = 8,
|
||||||
ESC_STR_END = 16, /* a final string was encountered */
|
ESC_STR_END = 16, /* a final string was encountered */
|
||||||
ESC_TEST = 32, /* Enter in test mode */
|
ESC_TEST = 32, /* Enter in test mode */
|
||||||
ESC_UTF8 = 64,
|
ESC_UTF8 = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Glyph attr; /* current char attributes */
|
Glyph attr; /* current char attributes */
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
char state;
|
char state;
|
||||||
} TCursor;
|
} TCursor;
|
||||||
|
|
||||||
/* Internal representation of the screen */
|
/* Internal representation of the screen */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int row; /* nb row */
|
int row; /* nb row */
|
||||||
int col; /* nb col */
|
int col; /* nb col */
|
||||||
Line *line; /* screen */
|
Line * line; /* screen */
|
||||||
Line *alt; /* alternate screen */
|
Line * alt; /* alternate screen */
|
||||||
int *dirty; /* dirtyness of lines */
|
int * dirty; /* dirtyness of lines */
|
||||||
TCursor c; /* cursor */
|
TCursor c; /* cursor */
|
||||||
int ocx; /* old cursor col */
|
int ocx; /* old cursor col */
|
||||||
int ocy; /* old cursor row */
|
int ocy; /* old cursor row */
|
||||||
int top; /* top scroll limit */
|
int top; /* top scroll limit */
|
||||||
int bot; /* bottom scroll limit */
|
int bot; /* bottom scroll limit */
|
||||||
int mode; /* terminal mode flags */
|
int mode; /* terminal mode flags */
|
||||||
int esc; /* escape state flags */
|
int esc; /* escape state flags */
|
||||||
char trantbl[4]; /* charset table translation */
|
char trantbl[4]; /* charset table translation */
|
||||||
int charset; /* current charset */
|
int charset; /* current charset */
|
||||||
int icharset; /* selected charset for sequence */
|
int icharset; /* selected charset for sequence */
|
||||||
int *tabs;
|
int * tabs;
|
||||||
Rune lastc; /* last printed char outside of sequence, 0 if control */
|
Rune lastc; /* last printed char outside of sequence, 0 if control */
|
||||||
} Term;
|
} Term;
|
||||||
|
|
||||||
/* CSI Escape sequence structs */
|
/* CSI Escape sequence structs */
|
||||||
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
|
/* ESC '[' [[ [<priv>] <arg> [;]] <mode> [<mode>]] */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char buf[ESC_BUF_SIZ]; /* raw string */
|
char buf[ESC_BUF_SIZ]; /* raw string */
|
||||||
size_t len; /* raw string length */
|
size_t len; /* raw string length */
|
||||||
char priv;
|
char priv;
|
||||||
int arg[ESC_ARG_SIZ];
|
int arg[ESC_ARG_SIZ];
|
||||||
int narg; /* nb of args */
|
int narg; /* nb of args */
|
||||||
char mode[2];
|
char mode[2];
|
||||||
} CSIEscape;
|
} CSIEscape;
|
||||||
|
|
||||||
/* STR Escape sequence structs */
|
/* STR Escape sequence structs */
|
||||||
/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
|
/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char type; /* ESC type ... */
|
char type; /* ESC type ... */
|
||||||
char *buf; /* allocated raw string */
|
char * buf; /* allocated raw string */
|
||||||
size_t siz; /* allocation size */
|
size_t siz; /* allocation size */
|
||||||
size_t len; /* raw string length */
|
size_t len; /* raw string length */
|
||||||
char *args[STR_ARG_SIZ];
|
char * args[STR_ARG_SIZ];
|
||||||
int narg; /* nb of args */
|
int narg; /* nb of args */
|
||||||
} STREscape;
|
} STREscape;
|
||||||
|
|
||||||
static void execsh(char *, char **);
|
static void execsh(char *, char **);
|
||||||
|
@ -141,60 +141,60 @@ static void csidump(void);
|
||||||
static void csihandle(void);
|
static void csihandle(void);
|
||||||
static void csiparse(void);
|
static void csiparse(void);
|
||||||
static void csireset(void);
|
static void csireset(void);
|
||||||
static int eschandle(uchar);
|
static int eschandle(uchar);
|
||||||
static void strdump(void);
|
static void strdump(void);
|
||||||
static void strhandle(void);
|
static void strhandle(void);
|
||||||
static void strparse(void);
|
static void strparse(void);
|
||||||
static void strreset(void);
|
static void strreset(void);
|
||||||
|
|
||||||
static void tprinter(char *, size_t);
|
static void tprinter(char *, size_t);
|
||||||
static void tdumpsel(void);
|
static void tdumpsel(void);
|
||||||
static void tdumpline(int);
|
static void tdumpline(int);
|
||||||
static void tdump(void);
|
static void tdump(void);
|
||||||
static void tclearregion(int, int, int, int);
|
static void tclearregion(int, int, int, int);
|
||||||
static void tcursor(int);
|
static void tcursor(int);
|
||||||
static void tdeletechar(int);
|
static void tdeletechar(int);
|
||||||
static void tdeleteline(int);
|
static void tdeleteline(int);
|
||||||
static void tinsertblank(int);
|
static void tinsertblank(int);
|
||||||
static void tinsertblankline(int);
|
static void tinsertblankline(int);
|
||||||
static int tlinelen(int);
|
static int tlinelen(int);
|
||||||
static void tmoveto(int, int);
|
static void tmoveto(int, int);
|
||||||
static void tmoveato(int, int);
|
static void tmoveato(int, int);
|
||||||
static void tnewline(int);
|
static void tnewline(int);
|
||||||
static void tputtab(int);
|
static void tputtab(int);
|
||||||
static void tputc(Rune);
|
static void tputc(Rune);
|
||||||
static void treset(void);
|
static void treset(void);
|
||||||
static void tscrollup(int, int);
|
static void tscrollup(int, int);
|
||||||
static void tscrolldown(int, int);
|
static void tscrolldown(int, int);
|
||||||
static void tsetattr(int *, int);
|
static void tsetattr(int *, int);
|
||||||
static void tsetchar(Rune, Glyph *, int, int);
|
static void tsetchar(Rune, Glyph *, int, int);
|
||||||
static void tsetdirt(int, int);
|
static void tsetdirt(int, int);
|
||||||
static void tsetscroll(int, int);
|
static void tsetscroll(int, int);
|
||||||
static void tswapscreen(void);
|
static void tswapscreen(void);
|
||||||
static void tsetmode(int, int, int *, int);
|
static void tsetmode(int, int, int *, int);
|
||||||
static int twrite(const char *, int, int);
|
static int twrite(const char *, int, int);
|
||||||
static void tfulldirt(void);
|
static void tfulldirt(void);
|
||||||
static void tcontrolcode(uchar);
|
static void tcontrolcode(uchar);
|
||||||
static void tdectest(char);
|
static void tdectest(char);
|
||||||
static void tdefutf8(char);
|
static void tdefutf8(char);
|
||||||
static int32_t tdefcolor(int *, int *, int);
|
static int32_t tdefcolor(int *, int *, int);
|
||||||
static void tdeftran(char);
|
static void tdeftran(char);
|
||||||
static void tstrsequence(uchar);
|
static void tstrsequence(uchar);
|
||||||
|
|
||||||
static void drawregion(int, int, int, int);
|
static void drawregion(int, int, int, int);
|
||||||
|
|
||||||
static char *base64dec(const char *);
|
static char *base64dec(const char *);
|
||||||
static char base64dec_getc(const char **);
|
static char base64dec_getc(const char **);
|
||||||
|
|
||||||
static ssize_t xwrite(int, const char *, size_t);
|
static ssize_t xwrite(int, const char *, size_t);
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
static Term term;
|
static Term term;
|
||||||
static CSIEscape csiescseq;
|
static CSIEscape csiescseq;
|
||||||
static STREscape strescseq;
|
static STREscape strescseq;
|
||||||
static int iofd = 1;
|
static int iofd = 1;
|
||||||
static int cmdfd;
|
static int cmdfd;
|
||||||
static pid_t pid;
|
static pid_t pid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as write, but ensures that all bytes are written to the descriptor
|
* Same as write, but ensures that all bytes are written to the descriptor
|
||||||
|
@ -203,11 +203,11 @@ static pid_t pid;
|
||||||
* @param p_file_desc file descriptor to write to; same logic as write
|
* @param p_file_desc file descriptor to write to; same logic as write
|
||||||
* @param p_str char array to write to the file descriptor
|
* @param p_str char array to write to the file descriptor
|
||||||
* @param p_nbytes amount of bytes to write
|
* @param p_nbytes amount of bytes to write
|
||||||
* @return p_nbytes if the write was successful, otherwise return negative error
|
* @return p_nbytes if the write was successful, otherwise return negative
|
||||||
* value of write
|
* error value of write
|
||||||
*/
|
*/
|
||||||
ssize_t xwrite(int p_file_desc, const char *p_str, size_t p_nbytes) {
|
ssize_t xwrite(int p_file_desc, const char *p_str, size_t p_nbytes) {
|
||||||
size_t aux = p_nbytes;
|
size_t aux = p_nbytes;
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
|
||||||
while (p_nbytes > 0) {
|
while (p_nbytes > 0) {
|
||||||
|
@ -290,7 +290,7 @@ char base64dec_getc(const char **src) {
|
||||||
|
|
||||||
char *base64dec(const char *src) {
|
char *base64dec(const char *src) {
|
||||||
size_t in_len = strlen(src);
|
size_t in_len = strlen(src);
|
||||||
char *result, *dst;
|
char * result, *dst;
|
||||||
|
|
||||||
if (in_len % 4)
|
if (in_len % 4)
|
||||||
in_len += 4 - (in_len % 4);
|
in_len += 4 - (in_len % 4);
|
||||||
|
@ -333,7 +333,7 @@ void selstart(int col, int row, int snap) {
|
||||||
selclear();
|
selclear();
|
||||||
sel.mode = SEL_EMPTY;
|
sel.mode = SEL_EMPTY;
|
||||||
sel.type = SEL_REGULAR;
|
sel.type = SEL_REGULAR;
|
||||||
sel.alt = IS_SET(MODE_ALTSCREEN);
|
sel.alt = IS_SET(MODE_ALTSCREEN);
|
||||||
sel.snap = snap;
|
sel.snap = snap;
|
||||||
sel.oe.x = sel.ob.x = col;
|
sel.oe.x = sel.ob.x = col;
|
||||||
sel.oe.y = sel.ob.y = row;
|
sel.oe.y = sel.ob.y = row;
|
||||||
|
@ -354,10 +354,10 @@ void selextend(int col, int row, int type, int done) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldey = sel.oe.y;
|
oldey = sel.oe.y;
|
||||||
oldex = sel.oe.x;
|
oldex = sel.oe.x;
|
||||||
oldsby = sel.nb.y;
|
oldsby = sel.nb.y;
|
||||||
oldsey = sel.ne.y;
|
oldsey = sel.ne.y;
|
||||||
oldtype = sel.type;
|
oldtype = sel.type;
|
||||||
|
|
||||||
sel.oe.x = col;
|
sel.oe.x = col;
|
||||||
|
@ -378,15 +378,17 @@ int selected(int x, int y) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (sel.type == SEL_RECTANGULAR)
|
if (sel.type == SEL_RECTANGULAR)
|
||||||
return BETWEEN(y, sel.nb.y, sel.ne.y) && BETWEEN(x, sel.nb.x, sel.ne.x);
|
return BETWEEN(y, sel.nb.y, sel.ne.y) &&
|
||||||
|
BETWEEN(x, sel.nb.x, sel.ne.x);
|
||||||
|
|
||||||
return BETWEEN(y, sel.nb.y, sel.ne.y) && (y != sel.nb.y || x >= sel.nb.x) &&
|
return BETWEEN(y, sel.nb.y, sel.ne.y) &&
|
||||||
|
(y != sel.nb.y || x >= sel.nb.x) &&
|
||||||
(y != sel.ne.y || x <= sel.ne.x);
|
(y != sel.ne.y || x <= sel.ne.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void selsnap(int *x, int *y, int direction) {
|
void selsnap(int *x, int *y, int direction) {
|
||||||
int newx, newy, xt, yt;
|
int newx, newy, xt, yt;
|
||||||
int delim, prevdelim;
|
int delim, prevdelim;
|
||||||
Glyph *gp, *prevgp;
|
Glyph *gp, *prevgp;
|
||||||
|
|
||||||
switch (sel.snap) {
|
switch (sel.snap) {
|
||||||
|
@ -395,7 +397,7 @@ void selsnap(int *x, int *y, int direction) {
|
||||||
* Snap around if the word wraps around at the end or
|
* Snap around if the word wraps around at the end or
|
||||||
* beginning of a line.
|
* beginning of a line.
|
||||||
*/
|
*/
|
||||||
prevgp = &term.line[*y][*x];
|
prevgp = &term.line[*y][*x];
|
||||||
prevdelim = ISDELIM(prevgp->u);
|
prevdelim = ISDELIM(prevgp->u);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
newx = *x + direction;
|
newx = *x + direction;
|
||||||
|
@ -417,15 +419,15 @@ void selsnap(int *x, int *y, int direction) {
|
||||||
if (newx >= tlinelen(newy))
|
if (newx >= tlinelen(newy))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
gp = &term.line[newy][newx];
|
gp = &term.line[newy][newx];
|
||||||
delim = ISDELIM(gp->u);
|
delim = ISDELIM(gp->u);
|
||||||
if (!(gp->mode & ATTR_WDUMMY) &&
|
if (!(gp->mode & ATTR_WDUMMY) &&
|
||||||
(delim != prevdelim || (delim && gp->u != prevgp->u)))
|
(delim != prevdelim || (delim && gp->u != prevgp->u)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
*x = newx;
|
*x = newx;
|
||||||
*y = newy;
|
*y = newy;
|
||||||
prevgp = gp;
|
prevgp = gp;
|
||||||
prevdelim = delim;
|
prevdelim = delim;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -454,8 +456,8 @@ void selsnap(int *x, int *y, int direction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getsel(void) {
|
char *getsel(void) {
|
||||||
char *str, *ptr;
|
char * str, *ptr;
|
||||||
int y, bufsize, lastx, linelen;
|
int y, bufsize, lastx, linelen;
|
||||||
Glyph *gp, *last;
|
Glyph *gp, *last;
|
||||||
|
|
||||||
if (sel.ob.x == -1)
|
if (sel.ob.x == -1)
|
||||||
|
@ -472,10 +474,10 @@ char *getsel(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sel.type == SEL_RECTANGULAR) {
|
if (sel.type == SEL_RECTANGULAR) {
|
||||||
gp = &term.line[y][sel.nb.x];
|
gp = &term.line[y][sel.nb.x];
|
||||||
lastx = sel.ne.x;
|
lastx = sel.ne.x;
|
||||||
} else {
|
} else {
|
||||||
gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
|
gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
|
||||||
lastx = (sel.ne.y == y) ? sel.ne.x : term.col - 1;
|
lastx = (sel.ne.y == y) ? sel.ne.x : term.col - 1;
|
||||||
}
|
}
|
||||||
last = &term.line[y][MIN(lastx, linelen - 1)];
|
last = &term.line[y][MIN(lastx, linelen - 1)];
|
||||||
|
@ -516,7 +518,7 @@ void die(const char *errstr, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void execsh(char *cmd, char **args) {
|
void execsh(char *cmd, char **args) {
|
||||||
char *sh, *prog, *arg;
|
char * sh, *prog, *arg;
|
||||||
const struct passwd *pw;
|
const struct passwd *pw;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -532,16 +534,16 @@ void execsh(char *cmd, char **args) {
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
prog = args[0];
|
prog = args[0];
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
} else if (scroll) {
|
} else if (scroll) {
|
||||||
prog = scroll;
|
prog = scroll;
|
||||||
arg = utmp ? utmp : sh;
|
arg = utmp ? utmp : sh;
|
||||||
} else if (utmp) {
|
} else if (utmp) {
|
||||||
prog = utmp;
|
prog = utmp;
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
} else {
|
} else {
|
||||||
prog = sh;
|
prog = sh;
|
||||||
arg = NULL;
|
arg = NULL;
|
||||||
}
|
}
|
||||||
DEFAULT(args, ((char *[]){prog, arg, NULL}));
|
DEFAULT(args, ((char *[]){prog, arg, NULL}));
|
||||||
|
|
||||||
|
@ -566,7 +568,7 @@ void execsh(char *cmd, char **args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sigchld(int a) {
|
void sigchld(int a) {
|
||||||
int stat;
|
int stat;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
|
|
||||||
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
||||||
|
@ -583,13 +585,13 @@ void sigchld(int a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void stty(char **args) {
|
void stty(char **args) {
|
||||||
char cmd[_POSIX_ARG_MAX], **p, *q, *s;
|
char cmd[_POSIX_ARG_MAX], **p, *q, *s;
|
||||||
size_t n, siz;
|
size_t n, siz;
|
||||||
|
|
||||||
if ((n = strlen(stty_args)) > sizeof(cmd) - 1)
|
if ((n = strlen(stty_args)) > sizeof(cmd) - 1)
|
||||||
die("incorrect stty parameters\n");
|
die("incorrect stty parameters\n");
|
||||||
memcpy(cmd, stty_args, n);
|
memcpy(cmd, stty_args, n);
|
||||||
q = cmd + n;
|
q = cmd + n;
|
||||||
siz = sizeof(cmd) - n;
|
siz = sizeof(cmd) - n;
|
||||||
for (p = args; p && (s = *p); ++p) {
|
for (p = args; p && (s = *p); ++p) {
|
||||||
if ((n = strlen(s)) > siz - 1)
|
if ((n = strlen(s)) > siz - 1)
|
||||||
|
@ -662,8 +664,8 @@ int ttynew(char *line, char *cmd, char *out, char **args) {
|
||||||
|
|
||||||
size_t ttyread(void) {
|
size_t ttyread(void) {
|
||||||
static char buf[BUFSIZ];
|
static char buf[BUFSIZ];
|
||||||
static int buflen = 0;
|
static int buflen = 0;
|
||||||
int ret, written;
|
int ret, written;
|
||||||
|
|
||||||
/* append read bytes to unprocessed bytes */
|
/* append read bytes to unprocessed bytes */
|
||||||
ret = read(cmdfd, buf + buflen, LEN(buf) - buflen);
|
ret = read(cmdfd, buf + buflen, LEN(buf) - buflen);
|
||||||
|
@ -711,9 +713,9 @@ void ttywrite(const char *s, size_t n, int may_echo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ttywriteraw(const char *s, size_t n) {
|
void ttywriteraw(const char *s, size_t n) {
|
||||||
fd_set wfd, rfd;
|
fd_set wfd, rfd;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
size_t lim = 256;
|
size_t lim = 256;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remember that we are using a pty, which might be a modem line.
|
* Remember that we are using a pty, which might be a modem line.
|
||||||
|
@ -768,8 +770,8 @@ write_error:
|
||||||
void ttyresize(int tw, int th) {
|
void ttyresize(int tw, int th) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
|
|
||||||
w.ws_row = term.row;
|
w.ws_row = term.row;
|
||||||
w.ws_col = term.col;
|
w.ws_col = term.col;
|
||||||
w.ws_xpixel = tw;
|
w.ws_xpixel = tw;
|
||||||
w.ws_ypixel = th;
|
w.ws_ypixel = th;
|
||||||
if (ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
|
if (ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
|
||||||
|
@ -821,7 +823,7 @@ void tfulldirt(void) { tsetdirt(0, term.row - 1); }
|
||||||
|
|
||||||
void tcursor(int mode) {
|
void tcursor(int mode) {
|
||||||
static TCursor c[2];
|
static TCursor c[2];
|
||||||
int alt = IS_SET(MODE_ALTSCREEN);
|
int alt = IS_SET(MODE_ALTSCREEN);
|
||||||
|
|
||||||
if (mode == CURSOR_SAVE) {
|
if (mode == CURSOR_SAVE) {
|
||||||
c[alt] = term.c;
|
c[alt] = term.c;
|
||||||
|
@ -835,15 +837,15 @@ void treset(void) {
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
term.c = (TCursor){{.mode = ATTR_NULL, .fg = defaultfg, .bg = defaultbg},
|
term.c = (TCursor){{.mode = ATTR_NULL, .fg = defaultfg, .bg = defaultbg},
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 0,
|
.y = 0,
|
||||||
.state = CURSOR_DEFAULT};
|
.state = CURSOR_DEFAULT};
|
||||||
|
|
||||||
memset(term.tabs, 0, term.col * sizeof(*term.tabs));
|
memset(term.tabs, 0, term.col * sizeof(*term.tabs));
|
||||||
for (i = tabspaces; i < term.col; i += tabspaces)
|
for (i = tabspaces; i < term.col; i += tabspaces)
|
||||||
term.tabs[i] = 1;
|
term.tabs[i] = 1;
|
||||||
term.top = 0;
|
term.top = 0;
|
||||||
term.bot = term.row - 1;
|
term.bot = term.row - 1;
|
||||||
term.mode = MODE_WRAP | MODE_UTF8;
|
term.mode = MODE_WRAP | MODE_UTF8;
|
||||||
memset(term.trantbl, CS_USA, sizeof(term.trantbl));
|
memset(term.trantbl, CS_USA, sizeof(term.trantbl));
|
||||||
term.charset = 0;
|
term.charset = 0;
|
||||||
|
@ -866,13 +868,13 @@ void tswapscreen(void) {
|
||||||
Line *tmp = term.line;
|
Line *tmp = term.line;
|
||||||
|
|
||||||
term.line = term.alt;
|
term.line = term.alt;
|
||||||
term.alt = tmp;
|
term.alt = tmp;
|
||||||
term.mode ^= MODE_ALTSCREEN;
|
term.mode ^= MODE_ALTSCREEN;
|
||||||
tfulldirt();
|
tfulldirt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscrolldown(int orig, int n) {
|
void tscrolldown(int orig, int n) {
|
||||||
int i;
|
int i;
|
||||||
Line temp;
|
Line temp;
|
||||||
|
|
||||||
LIMIT(n, 0, term.bot - orig + 1);
|
LIMIT(n, 0, term.bot - orig + 1);
|
||||||
|
@ -881,8 +883,8 @@ void tscrolldown(int orig, int n) {
|
||||||
tclearregion(0, term.bot - n + 1, term.col - 1, term.bot);
|
tclearregion(0, term.bot - n + 1, term.col - 1, term.bot);
|
||||||
|
|
||||||
for (i = term.bot; i >= orig + n; i--) {
|
for (i = term.bot; i >= orig + n; i--) {
|
||||||
temp = term.line[i];
|
temp = term.line[i];
|
||||||
term.line[i] = term.line[i - n];
|
term.line[i] = term.line[i - n];
|
||||||
term.line[i - n] = temp;
|
term.line[i - n] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,7 +892,7 @@ void tscrolldown(int orig, int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscrollup(int orig, int n) {
|
void tscrollup(int orig, int n) {
|
||||||
int i;
|
int i;
|
||||||
Line temp;
|
Line temp;
|
||||||
|
|
||||||
LIMIT(n, 0, term.bot - orig + 1);
|
LIMIT(n, 0, term.bot - orig + 1);
|
||||||
|
@ -899,8 +901,8 @@ void tscrollup(int orig, int n) {
|
||||||
tsetdirt(orig + n, term.bot);
|
tsetdirt(orig + n, term.bot);
|
||||||
|
|
||||||
for (i = orig; i <= term.bot - n; i++) {
|
for (i = orig; i <= term.bot - n; i++) {
|
||||||
temp = term.line[i];
|
temp = term.line[i];
|
||||||
term.line[i] = term.line[i + n];
|
term.line[i] = term.line[i + n];
|
||||||
term.line[i + n] = temp;
|
term.line[i + n] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,7 +921,7 @@ void tnewline(int first_col) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void csiparse(void) {
|
void csiparse(void) {
|
||||||
char *p = csiescseq.buf, *np;
|
char * p = csiescseq.buf, *np;
|
||||||
long int v;
|
long int v;
|
||||||
|
|
||||||
csiescseq.narg = 0;
|
csiescseq.narg = 0;
|
||||||
|
@ -931,13 +933,13 @@ void csiparse(void) {
|
||||||
csiescseq.buf[csiescseq.len] = '\0';
|
csiescseq.buf[csiescseq.len] = '\0';
|
||||||
while (p < csiescseq.buf + csiescseq.len) {
|
while (p < csiescseq.buf + csiescseq.len) {
|
||||||
np = NULL;
|
np = NULL;
|
||||||
v = strtol(p, &np, 10);
|
v = strtol(p, &np, 10);
|
||||||
if (np == p)
|
if (np == p)
|
||||||
v = 0;
|
v = 0;
|
||||||
if (v == LONG_MAX || v == LONG_MIN)
|
if (v == LONG_MAX || v == LONG_MIN)
|
||||||
v = -1;
|
v = -1;
|
||||||
csiescseq.arg[csiescseq.narg++] = v;
|
csiescseq.arg[csiescseq.narg++] = v;
|
||||||
p = np;
|
p = np;
|
||||||
if (*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
|
if (*p != ';' || csiescseq.narg == ESC_ARG_SIZ)
|
||||||
break;
|
break;
|
||||||
p++;
|
p++;
|
||||||
|
@ -996,13 +998,13 @@ void tsetchar(Rune u, Glyph *attr, int x, int y) {
|
||||||
term.line[y][x - 1].mode &= ~ATTR_WIDE;
|
term.line[y][x - 1].mode &= ~ATTR_WIDE;
|
||||||
}
|
}
|
||||||
|
|
||||||
term.dirty[y] = 1;
|
term.dirty[y] = 1;
|
||||||
term.line[y][x] = *attr;
|
term.line[y][x] = *attr;
|
||||||
term.line[y][x].u = u;
|
term.line[y][x].u = u;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tclearregion(int x1, int y1, int x2, int y2) {
|
void tclearregion(int x1, int y1, int x2, int y2) {
|
||||||
int x, y, temp;
|
int x, y, temp;
|
||||||
Glyph *gp;
|
Glyph *gp;
|
||||||
|
|
||||||
if (x1 > x2)
|
if (x1 > x2)
|
||||||
|
@ -1021,22 +1023,22 @@ void tclearregion(int x1, int y1, int x2, int y2) {
|
||||||
gp = &term.line[y][x];
|
gp = &term.line[y][x];
|
||||||
if (selected(x, y))
|
if (selected(x, y))
|
||||||
selclear();
|
selclear();
|
||||||
gp->fg = term.c.attr.fg;
|
gp->fg = term.c.attr.fg;
|
||||||
gp->bg = term.c.attr.bg;
|
gp->bg = term.c.attr.bg;
|
||||||
gp->mode = 0;
|
gp->mode = 0;
|
||||||
gp->u = ' ';
|
gp->u = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdeletechar(int n) {
|
void tdeletechar(int n) {
|
||||||
int dst, src, size;
|
int dst, src, size;
|
||||||
Glyph *line;
|
Glyph *line;
|
||||||
|
|
||||||
LIMIT(n, 0, term.col - term.c.x);
|
LIMIT(n, 0, term.col - term.c.x);
|
||||||
|
|
||||||
dst = term.c.x;
|
dst = term.c.x;
|
||||||
src = term.c.x + n;
|
src = term.c.x + n;
|
||||||
size = term.col - src;
|
size = term.col - src;
|
||||||
line = term.line[term.c.y];
|
line = term.line[term.c.y];
|
||||||
|
|
||||||
|
@ -1045,13 +1047,13 @@ void tdeletechar(int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tinsertblank(int n) {
|
void tinsertblank(int n) {
|
||||||
int dst, src, size;
|
int dst, src, size;
|
||||||
Glyph *line;
|
Glyph *line;
|
||||||
|
|
||||||
LIMIT(n, 0, term.col - term.c.x);
|
LIMIT(n, 0, term.col - term.c.x);
|
||||||
|
|
||||||
dst = term.c.x + n;
|
dst = term.c.x + n;
|
||||||
src = term.c.x;
|
src = term.c.x;
|
||||||
size = term.col - dst;
|
size = term.col - dst;
|
||||||
line = term.line[term.c.y];
|
line = term.line[term.c.y];
|
||||||
|
|
||||||
|
@ -1071,12 +1073,13 @@ void tdeleteline(int n) {
|
||||||
|
|
||||||
int32_t tdefcolor(int *attr, int *npar, int l) {
|
int32_t tdefcolor(int *attr, int *npar, int l) {
|
||||||
int32_t idx = -1;
|
int32_t idx = -1;
|
||||||
uint r, g, b;
|
uint r, g, b;
|
||||||
|
|
||||||
switch (attr[*npar + 1]) {
|
switch (attr[*npar + 1]) {
|
||||||
case 2: /* direct color in RGB space */
|
case 2: /* direct color in RGB space */
|
||||||
if (*npar + 4 >= l) {
|
if (*npar + 4 >= l) {
|
||||||
fprintf(stderr, "erresc(38): Incorrect number of parameters (%d)\n",
|
fprintf(stderr,
|
||||||
|
"erresc(38): Incorrect number of parameters (%d)\n",
|
||||||
*npar);
|
*npar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1091,7 +1094,8 @@ int32_t tdefcolor(int *attr, int *npar, int l) {
|
||||||
break;
|
break;
|
||||||
case 5: /* indexed color */
|
case 5: /* indexed color */
|
||||||
if (*npar + 2 >= l) {
|
if (*npar + 2 >= l) {
|
||||||
fprintf(stderr, "erresc(38): Incorrect number of parameters (%d)\n",
|
fprintf(stderr,
|
||||||
|
"erresc(38): Incorrect number of parameters (%d)\n",
|
||||||
*npar);
|
*npar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1114,7 +1118,7 @@ int32_t tdefcolor(int *attr, int *npar, int l) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsetattr(int *attr, int l) {
|
void tsetattr(int *attr, int l) {
|
||||||
int i;
|
int i;
|
||||||
int32_t idx;
|
int32_t idx;
|
||||||
|
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
|
@ -1213,8 +1217,8 @@ void tsetscroll(int t, int b) {
|
||||||
LIMIT(b, 0, term.row - 1);
|
LIMIT(b, 0, term.row - 1);
|
||||||
if (t > b) {
|
if (t > b) {
|
||||||
temp = t;
|
temp = t;
|
||||||
t = b;
|
t = b;
|
||||||
b = temp;
|
b = temp;
|
||||||
}
|
}
|
||||||
term.top = t;
|
term.top = t;
|
||||||
term.bot = b;
|
term.bot = b;
|
||||||
|
@ -1346,7 +1350,7 @@ void tsetmode(int priv, int set, int *args, int narg) {
|
||||||
|
|
||||||
void csihandle(void) {
|
void csihandle(void) {
|
||||||
char buf[40];
|
char buf[40];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
switch (csiescseq.mode[0]) {
|
switch (csiescseq.mode[0]) {
|
||||||
default:
|
default:
|
||||||
|
@ -1554,7 +1558,7 @@ void csihandle(void) {
|
||||||
|
|
||||||
void csidump(void) {
|
void csidump(void) {
|
||||||
size_t i;
|
size_t i;
|
||||||
uint c;
|
uint c;
|
||||||
|
|
||||||
fprintf(stderr, "ESC[");
|
fprintf(stderr, "ESC[");
|
||||||
for (i = 0; i < csiescseq.len; i++) {
|
for (i = 0; i < csiescseq.len; i++) {
|
||||||
|
@ -1578,7 +1582,7 @@ void csireset(void) { memset(&csiescseq, 0, sizeof(csiescseq)); }
|
||||||
|
|
||||||
void strhandle(void) {
|
void strhandle(void) {
|
||||||
char *p = NULL, *dec;
|
char *p = NULL, *dec;
|
||||||
int j, narg, par;
|
int j, narg, par;
|
||||||
|
|
||||||
term.esc &= ~(ESC_STR_END | ESC_STR);
|
term.esc &= ~(ESC_STR_END | ESC_STR);
|
||||||
strparse();
|
strparse();
|
||||||
|
@ -1648,10 +1652,10 @@ void strhandle(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void strparse(void) {
|
void strparse(void) {
|
||||||
int c;
|
int c;
|
||||||
char *p = strescseq.buf;
|
char *p = strescseq.buf;
|
||||||
|
|
||||||
strescseq.narg = 0;
|
strescseq.narg = 0;
|
||||||
strescseq.buf[strescseq.len] = '\0';
|
strescseq.buf[strescseq.len] = '\0';
|
||||||
|
|
||||||
if (*p == '\0')
|
if (*p == '\0')
|
||||||
|
@ -1669,7 +1673,7 @@ void strparse(void) {
|
||||||
|
|
||||||
void strdump(void) {
|
void strdump(void) {
|
||||||
size_t i;
|
size_t i;
|
||||||
uint c;
|
uint c;
|
||||||
|
|
||||||
fprintf(stderr, "ESC%c", strescseq.type);
|
fprintf(stderr, "ESC%c", strescseq.type);
|
||||||
for (i = 0; i < strescseq.len; i++) {
|
for (i = 0; i < strescseq.len; i++) {
|
||||||
|
@ -1728,10 +1732,10 @@ void tdumpsel(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdumpline(int n) {
|
void tdumpline(int n) {
|
||||||
char buf[UTF_SIZE];
|
char buf[UTF_SIZE];
|
||||||
Glyph *bp, *end;
|
Glyph *bp, *end;
|
||||||
|
|
||||||
bp = &term.line[n][0];
|
bp = &term.line[n][0];
|
||||||
end = &bp[MIN(tlinelen(n), term.col) - 1];
|
end = &bp[MIN(tlinelen(n), term.col) - 1];
|
||||||
if (bp != end || bp->u != ' ') {
|
if (bp != end || bp->u != ' ') {
|
||||||
for (; bp <= end; ++bp)
|
for (; bp <= end; ++bp)
|
||||||
|
@ -1770,9 +1774,9 @@ void tdefutf8(char ascii) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdeftran(char ascii) {
|
void tdeftran(char ascii) {
|
||||||
static char cs[] = "0B";
|
static char cs[] = "0B";
|
||||||
static int vcs[] = {CS_GRAPHIC0, CS_USA};
|
static int vcs[] = {CS_GRAPHIC0, CS_USA};
|
||||||
char *p;
|
char * p;
|
||||||
|
|
||||||
if ((p = strchr(cs, ascii)) == NULL) {
|
if ((p = strchr(cs, ascii)) == NULL) {
|
||||||
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
|
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
|
||||||
|
@ -1993,14 +1997,14 @@ int eschandle(uchar ascii) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tputc(Rune u) {
|
void tputc(Rune u) {
|
||||||
char c[UTF_SIZE];
|
char c[UTF_SIZE];
|
||||||
int control;
|
int control;
|
||||||
int width, len;
|
int width, len;
|
||||||
Glyph *gp;
|
Glyph *gp;
|
||||||
|
|
||||||
control = ISCONTROL(u);
|
control = ISCONTROL(u);
|
||||||
if (u < 127 || !IS_SET(MODE_UTF8)) {
|
if (u < 127 || !IS_SET(MODE_UTF8)) {
|
||||||
c[0] = u;
|
c[0] = u;
|
||||||
width = len = 1;
|
width = len = 1;
|
||||||
} else {
|
} else {
|
||||||
len = utf8encode(u, c);
|
len = utf8encode(u, c);
|
||||||
|
@ -2115,7 +2119,7 @@ check_control_code:
|
||||||
if (width == 2) {
|
if (width == 2) {
|
||||||
gp->mode |= ATTR_WIDE;
|
gp->mode |= ATTR_WIDE;
|
||||||
if (term.c.x + 1 < term.col) {
|
if (term.c.x + 1 < term.col) {
|
||||||
gp[1].u = '\0';
|
gp[1].u = '\0';
|
||||||
gp[1].mode = ATTR_WDUMMY;
|
gp[1].mode = ATTR_WDUMMY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2127,9 +2131,9 @@ check_control_code:
|
||||||
}
|
}
|
||||||
|
|
||||||
int twrite(const char *buf, int buflen, int show_ctrl) {
|
int twrite(const char *buf, int buflen, int show_ctrl) {
|
||||||
int charsize;
|
int charsize;
|
||||||
Rune u;
|
Rune u;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
for (n = 0; n < buflen; n += charsize) {
|
for (n = 0; n < buflen; n += charsize) {
|
||||||
if (IS_SET(MODE_UTF8)) {
|
if (IS_SET(MODE_UTF8)) {
|
||||||
|
@ -2138,7 +2142,7 @@ int twrite(const char *buf, int buflen, int show_ctrl) {
|
||||||
if (charsize == 0)
|
if (charsize == 0)
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
u = buf[n] & 0xFF;
|
u = buf[n] & 0xFF;
|
||||||
charsize = 1;
|
charsize = 1;
|
||||||
}
|
}
|
||||||
if (show_ctrl && ISCONTROL(u)) {
|
if (show_ctrl && ISCONTROL(u)) {
|
||||||
|
@ -2157,10 +2161,10 @@ int twrite(const char *buf, int buflen, int show_ctrl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tresize(int col, int row) {
|
void tresize(int col, int row) {
|
||||||
int i;
|
int i;
|
||||||
int minrow = MIN(row, term.row);
|
int minrow = MIN(row, term.row);
|
||||||
int mincol = MIN(col, term.col);
|
int mincol = MIN(col, term.col);
|
||||||
int *bp;
|
int * bp;
|
||||||
TCursor c;
|
TCursor c;
|
||||||
|
|
||||||
if (col < 1 || row < 1) {
|
if (col < 1 || row < 1) {
|
||||||
|
@ -2188,21 +2192,21 @@ void tresize(int col, int row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resize to new height */
|
/* resize to new height */
|
||||||
term.line = safe_realloc(term.line, row * sizeof(Line));
|
term.line = safe_realloc(term.line, row * sizeof(Line));
|
||||||
term.alt = safe_realloc(term.alt, row * sizeof(Line));
|
term.alt = safe_realloc(term.alt, row * sizeof(Line));
|
||||||
term.dirty = safe_realloc(term.dirty, row * sizeof(*term.dirty));
|
term.dirty = safe_realloc(term.dirty, row * sizeof(*term.dirty));
|
||||||
term.tabs = safe_realloc(term.tabs, col * sizeof(*term.tabs));
|
term.tabs = safe_realloc(term.tabs, col * sizeof(*term.tabs));
|
||||||
|
|
||||||
/* resize each row to new width, zero-pad if needed */
|
/* resize each row to new width, zero-pad if needed */
|
||||||
for (i = 0; i < minrow; i++) {
|
for (i = 0; i < minrow; i++) {
|
||||||
term.line[i] = safe_realloc(term.line[i], col * sizeof(Glyph));
|
term.line[i] = safe_realloc(term.line[i], col * sizeof(Glyph));
|
||||||
term.alt[i] = safe_realloc(term.alt[i], col * sizeof(Glyph));
|
term.alt[i] = safe_realloc(term.alt[i], col * sizeof(Glyph));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate any new rows */
|
/* allocate any new rows */
|
||||||
for (/* i = minrow */; i < row; i++) {
|
for (/* i = minrow */; i < row; i++) {
|
||||||
term.line[i] = safe_malloc(col * sizeof(Glyph));
|
term.line[i] = safe_malloc(col * sizeof(Glyph));
|
||||||
term.alt[i] = safe_malloc(col * sizeof(Glyph));
|
term.alt[i] = safe_malloc(col * sizeof(Glyph));
|
||||||
}
|
}
|
||||||
if (col > term.col) {
|
if (col > term.col) {
|
||||||
bp = term.tabs + term.col;
|
bp = term.tabs + term.col;
|
||||||
|
|
80
src/st/st.h
80
src/st/st.h
|
@ -11,35 +11,35 @@
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
enum glyph_attribute {
|
enum glyph_attribute {
|
||||||
ATTR_NULL = 0,
|
ATTR_NULL = 0,
|
||||||
ATTR_BOLD = 1 << 0,
|
ATTR_BOLD = 1 << 0,
|
||||||
ATTR_FAINT = 1 << 1,
|
ATTR_FAINT = 1 << 1,
|
||||||
ATTR_ITALIC = 1 << 2,
|
ATTR_ITALIC = 1 << 2,
|
||||||
ATTR_UNDERLINE = 1 << 3,
|
ATTR_UNDERLINE = 1 << 3,
|
||||||
ATTR_BLINK = 1 << 4,
|
ATTR_BLINK = 1 << 4,
|
||||||
ATTR_REVERSE = 1 << 5,
|
ATTR_REVERSE = 1 << 5,
|
||||||
ATTR_INVISIBLE = 1 << 6,
|
ATTR_INVISIBLE = 1 << 6,
|
||||||
ATTR_STRUCK = 1 << 7,
|
ATTR_STRUCK = 1 << 7,
|
||||||
ATTR_WRAP = 1 << 8,
|
ATTR_WRAP = 1 << 8,
|
||||||
ATTR_WIDE = 1 << 9,
|
ATTR_WIDE = 1 << 9,
|
||||||
ATTR_WDUMMY = 1 << 10,
|
ATTR_WDUMMY = 1 << 10,
|
||||||
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define Glyph Glyph_
|
#define Glyph Glyph_
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Rune u; /* character code */
|
Rune u; /* character code */
|
||||||
ushort mode; /* attribute flags */
|
ushort mode; /* attribute flags */
|
||||||
uint32_t fg; /* foreground */
|
uint32_t fg; /* foreground */
|
||||||
uint32_t bg; /* background */
|
uint32_t bg; /* background */
|
||||||
} Glyph;
|
} Glyph;
|
||||||
|
|
||||||
typedef Glyph *Line;
|
typedef Glyph *Line;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
int i;
|
int i;
|
||||||
uint ui;
|
uint ui;
|
||||||
float f;
|
float f;
|
||||||
const void *v;
|
const void *v;
|
||||||
const char *s;
|
const char *s;
|
||||||
} Arg;
|
} Arg;
|
||||||
|
@ -53,23 +53,23 @@ void printsel(const Arg *);
|
||||||
void sendbreak(const Arg *);
|
void sendbreak(const Arg *);
|
||||||
void toggleprinter(const Arg *);
|
void toggleprinter(const Arg *);
|
||||||
|
|
||||||
int tattrset(int);
|
int tattrset(int);
|
||||||
void tnew(int, int);
|
void tnew(int, int);
|
||||||
void tresize(int, int);
|
void tresize(int, int);
|
||||||
void tsetdirtattr(int);
|
void tsetdirtattr(int);
|
||||||
void ttyhangup(void);
|
void ttyhangup(void);
|
||||||
int ttynew(char *, char *, char *, char **);
|
int ttynew(char *, char *, char *, char **);
|
||||||
size_t ttyread(void);
|
size_t ttyread(void);
|
||||||
void ttyresize(int, int);
|
void ttyresize(int, int);
|
||||||
void ttywrite(const char *, size_t, int);
|
void ttywrite(const char *, size_t, int);
|
||||||
|
|
||||||
void resettitle(void);
|
void resettitle(void);
|
||||||
|
|
||||||
void selclear(void);
|
void selclear(void);
|
||||||
void selinit(void);
|
void selinit(void);
|
||||||
void selstart(int, int, int);
|
void selstart(int, int, int);
|
||||||
void selextend(int, int, int, int);
|
void selextend(int, int, int, int);
|
||||||
int selected(int, int);
|
int selected(int, int);
|
||||||
char *getsel(void);
|
char *getsel(void);
|
||||||
|
|
||||||
size_t utf8encode(Rune, char *);
|
size_t utf8encode(Rune, char *);
|
||||||
|
@ -79,14 +79,14 @@ void *safe_realloc(void *, size_t);
|
||||||
char *safe_strdup(char *);
|
char *safe_strdup(char *);
|
||||||
|
|
||||||
/* config.h globals */
|
/* config.h globals */
|
||||||
extern char *utmp;
|
extern char * utmp;
|
||||||
extern char *scroll;
|
extern char * scroll;
|
||||||
extern char *stty_args;
|
extern char * stty_args;
|
||||||
extern char *vtiden;
|
extern char * vtiden;
|
||||||
extern wchar_t *worddelimiters;
|
extern wchar_t * worddelimiters;
|
||||||
extern int allowaltscreen;
|
extern int allowaltscreen;
|
||||||
extern int allowwindowops;
|
extern int allowwindowops;
|
||||||
extern char *termname;
|
extern char * termname;
|
||||||
extern unsigned int tabspaces;
|
extern unsigned int tabspaces;
|
||||||
extern unsigned int defaultfg;
|
extern unsigned int defaultfg;
|
||||||
extern unsigned int defaultbg;
|
extern unsigned int defaultbg;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
typedef unsigned char uchar;
|
typedef unsigned char uchar;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
typedef unsigned long ulong;
|
typedef unsigned long ulong;
|
||||||
typedef unsigned short ushort;
|
typedef unsigned short ushort;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
static uchar utfbyte[UTF_SIZE + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
static uchar utfbyte[UTF_SIZE + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
||||||
static uchar utfmask[UTF_SIZE + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
|
static uchar utfmask[UTF_SIZE + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
|
||||||
static Rune utfmin[UTF_SIZE + 1] = {0, 0, 0x80, 0x800, 0x10000};
|
static Rune utfmin[UTF_SIZE + 1] = {0, 0, 0x80, 0x800, 0x10000};
|
||||||
static Rune utfmax[UTF_SIZE + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
static Rune utfmax[UTF_SIZE + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a given char array into a utf8 Rune
|
* Decode a given char array into a utf8 Rune
|
||||||
|
@ -17,7 +17,7 @@ static Rune utfmax[UTF_SIZE + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||||
*/
|
*/
|
||||||
size_t utf8decode(const char *p_char, Rune *p_rune, size_t p_char_len) {
|
size_t utf8decode(const char *p_char, Rune *p_rune, size_t p_char_len) {
|
||||||
size_t decoded_len, type, i;
|
size_t decoded_len, type, i;
|
||||||
Rune decoded_rune;
|
Rune decoded_rune;
|
||||||
|
|
||||||
*p_rune = UTF_INVALID;
|
*p_rune = UTF_INVALID;
|
||||||
if (!p_char_len) // p_char_len is 0, so just return 0
|
if (!p_char_len) // p_char_len is 0, so just return 0
|
||||||
|
@ -82,7 +82,9 @@ size_t utf8encode(Rune p_rune, char *p_char) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
char utf8encodebyte(Rune u, size_t i) { return utfbyte[i] | (u & ~utfmask[i]); }
|
char utf8encodebyte(Rune u, size_t i) {
|
||||||
|
return utfbyte[i] | (u & ~utfmask[i]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given rune is a valid UTF-8 rune
|
* Check if a given rune is a valid UTF-8 rune
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define UTF_INVALID 0xFFFD
|
#define UTF_INVALID 0xFFFD
|
||||||
#define UTF_SIZE 4
|
#define UTF_SIZE 4
|
||||||
|
|
||||||
typedef uint_least32_t Rune;
|
typedef uint_least32_t Rune;
|
||||||
|
|
||||||
size_t utf8decode(const char *, Rune *, size_t);
|
size_t utf8decode(const char *, Rune *, size_t);
|
||||||
Rune utf8decodebyte(char, size_t *);
|
Rune utf8decodebyte(char, size_t *);
|
||||||
char utf8encodebyte(Rune, size_t);
|
char utf8encodebyte(Rune, size_t);
|
||||||
size_t utf8validate(Rune *, size_t);
|
size_t utf8validate(Rune *, size_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
46
src/win.h
46
src/win.h
|
@ -6,26 +6,26 @@
|
||||||
#include "st/st.h"
|
#include "st/st.h"
|
||||||
|
|
||||||
enum win_mode {
|
enum win_mode {
|
||||||
MODE_VISIBLE = 1 << 0,
|
MODE_VISIBLE = 1 << 0,
|
||||||
MODE_FOCUSED = 1 << 1,
|
MODE_FOCUSED = 1 << 1,
|
||||||
MODE_APPKEYPAD = 1 << 2,
|
MODE_APPKEYPAD = 1 << 2,
|
||||||
MODE_MOUSEBTN = 1 << 3,
|
MODE_MOUSEBTN = 1 << 3,
|
||||||
MODE_MOUSEMOTION = 1 << 4,
|
MODE_MOUSEMOTION = 1 << 4,
|
||||||
MODE_REVERSE = 1 << 5,
|
MODE_REVERSE = 1 << 5,
|
||||||
MODE_KBDLOCK = 1 << 6,
|
MODE_KBDLOCK = 1 << 6,
|
||||||
MODE_HIDE = 1 << 7,
|
MODE_HIDE = 1 << 7,
|
||||||
MODE_APPCURSOR = 1 << 8,
|
MODE_APPCURSOR = 1 << 8,
|
||||||
MODE_MOUSESGR = 1 << 9,
|
MODE_MOUSESGR = 1 << 9,
|
||||||
MODE_8BIT = 1 << 10,
|
MODE_8BIT = 1 << 10,
|
||||||
MODE_BLINK = 1 << 11,
|
MODE_BLINK = 1 << 11,
|
||||||
MODE_FBLINK = 1 << 12,
|
MODE_FBLINK = 1 << 12,
|
||||||
MODE_FOCUS = 1 << 13,
|
MODE_FOCUS = 1 << 13,
|
||||||
MODE_MOUSEX10 = 1 << 14,
|
MODE_MOUSEX10 = 1 << 14,
|
||||||
MODE_MOUSEMANY = 1 << 15,
|
MODE_MOUSEMANY = 1 << 15,
|
||||||
MODE_BRCKTPASTE = 1 << 16,
|
MODE_BRCKTPASTE = 1 << 16,
|
||||||
MODE_NUMLOCK = 1 << 17,
|
MODE_NUMLOCK = 1 << 17,
|
||||||
MODE_MOUSE =
|
MODE_MOUSE =
|
||||||
MODE_MOUSEBTN | MODE_MOUSEMOTION | MODE_MOUSEX10 | MODE_MOUSEMANY,
|
MODE_MOUSEBTN | MODE_MOUSEMOTION | MODE_MOUSEX10 | MODE_MOUSEMANY,
|
||||||
};
|
};
|
||||||
|
|
||||||
void xbell(void);
|
void xbell(void);
|
||||||
|
@ -34,14 +34,14 @@ void xdrawcursor(int, int, Glyph, int, int, Glyph);
|
||||||
void xdrawline(Line, int, int, int);
|
void xdrawline(Line, int, int, int);
|
||||||
void xfinishdraw(void);
|
void xfinishdraw(void);
|
||||||
void xloadcols(void);
|
void xloadcols(void);
|
||||||
int xsetcolorname(int, const char *);
|
int xsetcolorname(int, const char *);
|
||||||
void xseticontitle(char *);
|
void xseticontitle(char *);
|
||||||
void xsettitle(char *);
|
void xsettitle(char *);
|
||||||
int xsetcursor(int);
|
int xsetcursor(int);
|
||||||
void xsetmode(int, unsigned int);
|
void xsetmode(int, unsigned int);
|
||||||
void xsetpointermotion(int);
|
void xsetpointermotion(int);
|
||||||
void xsetsel(char *);
|
void xsetsel(char *);
|
||||||
int xstartdraw(void);
|
int xstartdraw(void);
|
||||||
void xximspot(int, int);
|
void xximspot(int, int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Reference in New Issue