Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
673210b0
Commit
673210b0
authored
6 months ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Save and restore the console state for ANSI and Win32Console
Now it doesn't leave the console all messed up.
parent
6c4d4a18
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#6918
failed
6 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/conio/ansi_cio.c
+23
-2
23 additions, 2 deletions
src/conio/ansi_cio.c
src/conio/win32cio.c
+18
-7
18 additions, 7 deletions
src/conio/win32cio.c
with
41 additions
and
9 deletions
src/conio/ansi_cio.c
+
23
−
2
View file @
673210b0
...
@@ -68,6 +68,12 @@ static int ansi_raw_inch;
...
@@ -68,6 +68,12 @@ static int ansi_raw_inch;
static
WORD
*
ansivmem
;
static
WORD
*
ansivmem
;
static
int
force_move
=
1
;
static
int
force_move
=
1
;
static
DWORD
orig_in_mode
;
static
DWORD
orig_out_mode
;
static
CONSOLE_SCREEN_BUFFER_INFOEX
orig_sbiex
=
{
.
cbSize
=
sizeof
(
CONSOLE_SCREEN_BUFFER_INFOEX
),
};
/* Control sequence table definitions. */
/* Control sequence table definitions. */
typedef
struct
typedef
struct
{
{
...
@@ -908,12 +914,20 @@ void ansi_textmode(int mode)
...
@@ -908,12 +914,20 @@ void ansi_textmode(int mode)
ansiy
=
1
;
ansiy
=
1
;
}
}
#ifdef __unix__
void
ansi_fixterm
(
void
)
void
ansi_fixterm
(
void
)
{
{
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
tio_default
);
#ifdef _WIN32
if
(
isatty
(
fileno
(
stdin
)))
SetConsoleMode
(
GetStdHandle
(
STD_INPUT_HANDLE
),
orig_in_mode
);
if
(
isatty
(
fileno
(
stdout
)))
{
HANDLE
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
SetConsoleMode
(
h
,
orig_out_mode
);
SetConsoleScreenBufferInfoEx
(
h
,
&
orig_sbiex
);
}
}
#else
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
tio_default
);
#endif
#endif
}
#ifndef ENABLE_EXTENDED_FLAGS
#ifndef ENABLE_EXTENDED_FLAGS
#define ENABLE_INSERT_MODE 0x0020
#define ENABLE_INSERT_MODE 0x0020
...
@@ -951,6 +965,7 @@ int ansi_initio_cb(void)
...
@@ -951,6 +965,7 @@ int ansi_initio_cb(void)
HANDLE
h
;
HANDLE
h
;
if
(
isatty
(
fileno
(
stdin
)))
{
if
(
isatty
(
fileno
(
stdin
)))
{
h
=
GetStdHandle
(
STD_INPUT_HANDLE
);
h
=
GetStdHandle
(
STD_INPUT_HANDLE
);
GetConsoleMode
(
h
,
&
orig_in_mode
);
conmode
=
ENABLE_VIRTUAL_TERMINAL_INPUT
;
conmode
=
ENABLE_VIRTUAL_TERMINAL_INPUT
;
if
(
!
SetConsoleMode
(
h
,
conmode
))
if
(
!
SetConsoleMode
(
h
,
conmode
))
return
(
0
);
return
(
0
);
...
@@ -958,6 +973,11 @@ int ansi_initio_cb(void)
...
@@ -958,6 +973,11 @@ int ansi_initio_cb(void)
if
(
isatty
(
fileno
(
stdout
)))
{
if
(
isatty
(
fileno
(
stdout
)))
{
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
GetConsoleMode
(
h
,
&
orig_out_mode
);
GetConsoleScreenBufferInfoEx
(
h
,
&
orig_sbiex
);
// FFS Microsoft, get your shut together.
orig_sbiex
.
srWindow
.
Bottom
++
;
orig_sbiex
.
srWindow
.
Right
++
;
conmode
=
ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
ENABLE_PROCESSED_OUTPUT
;
conmode
=
ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
ENABLE_PROCESSED_OUTPUT
;
if
(
!
SetConsoleMode
(
h
,
conmode
))
if
(
!
SetConsoleMode
(
h
,
conmode
))
return
(
0
);
return
(
0
);
...
@@ -984,6 +1004,7 @@ int ansi_initio_cb(void)
...
@@ -984,6 +1004,7 @@ int ansi_initio_cb(void)
ansi_writestr_cb
(
seq
,
slen
);
ansi_writestr_cb
(
seq
,
slen
);
}
}
}
}
atexit
(
ansi_fixterm
);
#else
#else
struct
termios
tio_raw
;
struct
termios
tio_raw
;
...
...
This diff is collapsed.
Click to expand it.
src/conio/win32cio.c
+
18
−
7
View file @
673210b0
...
@@ -390,6 +390,9 @@ int win32_getch(void)
...
@@ -390,6 +390,9 @@ int win32_getch(void)
static
DWORD
orig_in_conmode
=
0
;
static
DWORD
orig_in_conmode
=
0
;
static
DWORD
orig_out_conmode
=
0
;
static
DWORD
orig_out_conmode
=
0
;
static
CONSOLE_SCREEN_BUFFER_INFOEX
orig_sbiex
=
{
.
cbSize
=
sizeof
(
CONSOLE_SCREEN_BUFFER_INFOEX
),
};
static
void
*
win32_suspendbuf
=
NULL
;
static
void
*
win32_suspendbuf
=
NULL
;
#ifndef CONSOLE_FULLSCREEN_MODE
#ifndef CONSOLE_FULLSCREEN_MODE
...
@@ -484,12 +487,6 @@ BOOL NT_GetConsoleDisplayMode(DWORD* mode)
...
@@ -484,12 +487,6 @@ BOOL NT_GetConsoleDisplayMode(DWORD* mode)
}
}
void
RestoreDisplayMode
(
void
)
{
if
(
orig_display_mode
==
0
)
NT_SetConsoleDisplayMode
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
CONSOLE_WINDOWED_MODE
);
}
void
win32_suspend
(
void
)
void
win32_suspend
(
void
)
{
{
HANDLE
h
;
HANDLE
h
;
...
@@ -500,6 +497,16 @@ void win32_suspend(void)
...
@@ -500,6 +497,16 @@ void win32_suspend(void)
SetConsoleMode
(
h
,
orig_in_conmode
);
SetConsoleMode
(
h
,
orig_in_conmode
);
}
}
void
RestoreDisplayMode
(
void
)
{
HANDLE
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
if
(
orig_display_mode
==
0
)
NT_SetConsoleDisplayMode
(
h
,
CONSOLE_WINDOWED_MODE
);
win32_suspend
();
SetConsoleScreenBufferInfoEx
(
h
,
&
orig_sbiex
);
SetConsoleScreenBufferInfoEx
(
h
,
&
orig_sbiex
);
}
void
win32_resume
(
void
)
void
win32_resume
(
void
)
{
{
DWORD
conmode
;
DWORD
conmode
;
...
@@ -545,6 +552,10 @@ int win32_initciolib(int inmode)
...
@@ -545,6 +552,10 @@ int win32_initciolib(int inmode)
if
((
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
))
==
INVALID_HANDLE_VALUE
if
((
h
=
GetStdHandle
(
STD_OUTPUT_HANDLE
))
==
INVALID_HANDLE_VALUE
||
!
GetConsoleMode
(
h
,
&
orig_out_conmode
))
||
!
GetConsoleMode
(
h
,
&
orig_out_conmode
))
return
(
0
);
return
(
0
);
GetConsoleScreenBufferInfoEx
(
h
,
&
orig_sbiex
);
// FFS Microsoft, get your shut together.
orig_sbiex
.
srWindow
.
Bottom
++
;
orig_sbiex
.
srWindow
.
Right
++
;
conmode
=
orig_out_conmode
;
conmode
=
orig_out_conmode
;
conmode
&=~
ENABLE_PROCESSED_OUTPUT
;
conmode
&=~
ENABLE_PROCESSED_OUTPUT
;
conmode
&=~
ENABLE_WRAP_AT_EOL_OUTPUT
;
conmode
&=~
ENABLE_WRAP_AT_EOL_OUTPUT
;
...
@@ -623,8 +634,8 @@ int win32_initciolib(int inmode)
...
@@ -623,8 +634,8 @@ int win32_initciolib(int inmode)
NT_GetConsoleDisplayMode
(
&
orig_display_mode
);
NT_GetConsoleDisplayMode
(
&
orig_display_mode
);
if
(
inmode
==
CIOLIB_MODE_CONIO_FULLSCREEN
)
{
if
(
inmode
==
CIOLIB_MODE_CONIO_FULLSCREEN
)
{
NT_SetConsoleDisplayMode
(
h
,
CONSOLE_FULLSCREEN_MODE
);
NT_SetConsoleDisplayMode
(
h
,
CONSOLE_FULLSCREEN_MODE
);
atexit
(
RestoreDisplayMode
);
}
}
atexit
(
RestoreDisplayMode
);
cio_api
.
mouse
=
1
;
cio_api
.
mouse
=
1
;
cio_api
.
options
=
CONIO_OPT_BRIGHT_BACKGROUND
|
CONIO_OPT_CUSTOM_CURSOR
|
CONIO_OPT_SET_TITLE
;
cio_api
.
options
=
CONIO_OPT_BRIGHT_BACKGROUND
|
CONIO_OPT_CUSTOM_CURSOR
|
CONIO_OPT_SET_TITLE
;
return
(
1
);
return
(
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment