Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
b4a2a1a8
Commit
b4a2a1a8
authored
Aug 04, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added raw mode to simplify the interface with other programs
parent
2eff957f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
12 deletions
+63
-12
src/cli/cli_main.cpp
src/cli/cli_main.cpp
+2
-1
src/cli/text_io_handler.cpp
src/cli/text_io_handler.cpp
+40
-10
src/cli/text_io_handler.hpp
src/cli/text_io_handler.hpp
+8
-0
src/main.cpp
src/main.cpp
+13
-1
No files found.
src/cli/cli_main.cpp
View file @
b4a2a1a8
...
@@ -65,11 +65,11 @@ void CLISetInterface::onChangeSet() {
...
@@ -65,11 +65,11 @@ void CLISetInterface::onChangeSet() {
void
CLISetInterface
::
run
()
{
void
CLISetInterface
::
run
()
{
// show welcome logo
// show welcome logo
if
(
!
quiet
)
showWelcome
();
if
(
!
quiet
)
showWelcome
();
handle_pending_errors
();
// loop
// loop
running
=
true
;
running
=
true
;
while
(
running
)
{
while
(
running
)
{
if
(
!
cli
.
canGetLine
())
break
;
if
(
!
cli
.
canGetLine
())
break
;
handle_pending_errors
();
// show prompt
// show prompt
if
(
!
quiet
)
{
if
(
!
quiet
)
{
cli
<<
GRAY
<<
_
(
"> "
)
<<
NORMAL
;
cli
<<
GRAY
<<
_
(
"> "
)
<<
NORMAL
;
...
@@ -79,6 +79,7 @@ void CLISetInterface::run() {
...
@@ -79,6 +79,7 @@ void CLISetInterface::run() {
String
command
=
cli
.
getLine
();
String
command
=
cli
.
getLine
();
handleCommand
(
command
);
handleCommand
(
command
);
cli
.
flush
();
cli
.
flush
();
cli
.
flushRaw
();
}
}
}
}
...
...
src/cli/text_io_handler.cpp
View file @
b4a2a1a8
...
@@ -56,7 +56,9 @@ void TextIOHandler::init() {
...
@@ -56,7 +56,9 @@ void TextIOHandler::init() {
have_stderr
=
true
;
have_stderr
=
true
;
escapes
=
true
;
// TODO: detect output redirection
escapes
=
true
;
// TODO: detect output redirection
#endif
#endif
// write to standard output
stream
=
stdout
;
stream
=
stdout
;
raw_mode
=
false
;
// always write to stderr if possible
// always write to stderr if possible
if
(
have_console
)
{
if
(
have_console
)
{
write_errors_to_cli
=
true
;
write_errors_to_cli
=
true
;
...
@@ -71,8 +73,8 @@ bool TextIOHandler::haveConsole() const {
...
@@ -71,8 +73,8 @@ bool TextIOHandler::haveConsole() const {
// ----------------------------------------------------------------------------- : Output
// ----------------------------------------------------------------------------- : Output
TextIOHandler
&
TextIOHandler
::
operator
<<
(
const
Char
*
str
)
{
TextIOHandler
&
TextIOHandler
::
operator
<<
(
const
Char
*
str
)
{
if
(
escapes
||
str
[
0
]
!=
27
)
{
if
(
(
escapes
&&
!
raw_mode
)
||
str
[
0
]
!=
27
)
{
if
(
have_console
)
{
if
(
have_console
&&
!
raw_mode
)
{
IF_UNICODE
(
fwprintf
,
fprintf
)(
stream
,
str
);
IF_UNICODE
(
fwprintf
,
fprintf
)(
stream
,
str
);
}
else
{
}
else
{
buffer
+=
str
;
buffer
+=
str
;
...
@@ -82,17 +84,11 @@ TextIOHandler& TextIOHandler::operator << (const Char* str) {
...
@@ -82,17 +84,11 @@ TextIOHandler& TextIOHandler::operator << (const Char* str) {
}
}
TextIOHandler
&
TextIOHandler
::
operator
<<
(
const
String
&
str
)
{
TextIOHandler
&
TextIOHandler
::
operator
<<
(
const
String
&
str
)
{
if
(
escapes
||
str
.
empty
()
||
str
.
GetChar
(
0
)
!=
27
)
{
return
*
this
<<
str
.
c_str
();
if
(
have_console
)
{
IF_UNICODE
(
fwprintf
,
fprintf
)(
stream
,
str
.
c_str
());
}
else
{
buffer
+=
str
;
}
}
return
*
this
;
}
}
void
TextIOHandler
::
flush
()
{
void
TextIOHandler
::
flush
()
{
if
(
raw_mode
)
return
;
if
(
have_console
)
{
if
(
have_console
)
{
fflush
(
stream
);
fflush
(
stream
);
}
else
if
(
!
buffer
.
empty
())
{
}
else
if
(
!
buffer
.
empty
())
{
...
@@ -124,6 +120,38 @@ bool TextIOHandler::canGetLine() {
...
@@ -124,6 +120,38 @@ bool TextIOHandler::canGetLine() {
return
!
feof
(
stdin
);
return
!
feof
(
stdin
);
}
}
// ----------------------------------------------------------------------------- : Raw mode
void
TextIOHandler
::
enableRaw
()
{
raw_mode
=
true
;
raw_mode_status
=
0
;
}
void
TextIOHandler
::
flushRaw
()
{
if
(
!
raw_mode
)
return
;
// always end in a newline
if
(
!
buffer
.
empty
()
&&
buffer
.
GetChar
(
buffer
.
size
()
-
1
)
!=
_
(
'\n'
))
{
buffer
+=
_
(
'\n'
);
}
// count newlines
int
newline_count
=
0
;
FOR_EACH_CONST
(
c
,
buffer
)
if
(
c
==
_
(
'\n'
))
newline_count
++
;
// write record
printf
(
"%d
\n
%d
\n
"
,
raw_mode_status
,
newline_count
);
if
(
!
buffer
.
empty
())
{
#ifdef UNICODE
wxCharBuffer
buf
=
buffer
.
mb_str
(
wxConvUTF8
);
puts
(
buf
);
#else
puts
(
buffer
.
c_str
());
#endif
}
fflush
(
stdout
);
// clear
buffer
.
clear
();
raw_mode_status
=
0
;
}
// ----------------------------------------------------------------------------- : Errors
// ----------------------------------------------------------------------------- : Errors
void
TextIOHandler
::
showError
(
const
String
&
message
)
{
void
TextIOHandler
::
showError
(
const
String
&
message
)
{
...
@@ -131,6 +159,7 @@ void TextIOHandler::showError(const String& message) {
...
@@ -131,6 +159,7 @@ void TextIOHandler::showError(const String& message) {
*
this
<<
RED
<<
_
(
"ERROR: "
)
<<
NORMAL
<<
replace_all
(
message
,
_
(
"
\n
"
),
_
(
"
\n
"
))
<<
ENDL
;
*
this
<<
RED
<<
_
(
"ERROR: "
)
<<
NORMAL
<<
replace_all
(
message
,
_
(
"
\n
"
),
_
(
"
\n
"
))
<<
ENDL
;
flush
();
flush
();
stream
=
stdout
;
stream
=
stdout
;
if
(
raw_mode
)
raw_mode_status
=
max
(
raw_mode_status
,
2
);
}
}
void
TextIOHandler
::
showWarning
(
const
String
&
message
)
{
void
TextIOHandler
::
showWarning
(
const
String
&
message
)
{
...
@@ -138,4 +167,5 @@ void TextIOHandler::showWarning(const String& message) {
...
@@ -138,4 +167,5 @@ void TextIOHandler::showWarning(const String& message) {
*
this
<<
YELLOW
<<
_
(
"WARNING: "
)
<<
NORMAL
<<
replace_all
(
message
,
_
(
"
\n
"
),
_
(
"
\n
"
))
<<
ENDL
;
*
this
<<
YELLOW
<<
_
(
"WARNING: "
)
<<
NORMAL
<<
replace_all
(
message
,
_
(
"
\n
"
),
_
(
"
\n
"
))
<<
ENDL
;
flush
();
flush
();
stream
=
stdout
;
stream
=
stdout
;
if
(
raw_mode
)
raw_mode_status
=
max
(
raw_mode_status
,
1
);
}
}
src/cli/text_io_handler.hpp
View file @
b4a2a1a8
...
@@ -41,11 +41,19 @@ class TextIOHandler {
...
@@ -41,11 +41,19 @@ class TextIOHandler {
/// Show a warning message
/// Show a warning message
void
showWarning
(
const
String
&
message
);
void
showWarning
(
const
String
&
message
);
/// Enable raw mode
void
enableRaw
();
/// Output a single raw-mode record
/// Has no effect unless enableRaw() was called
void
flushRaw
();
private:
private:
bool
have_console
;
bool
have_console
;
bool
escapes
;
bool
escapes
;
FILE
*
stream
;
FILE
*
stream
;
String
buffer
;
///< Buffer when not writing to console
String
buffer
;
///< Buffer when not writing to console
bool
raw_mode
;
int
raw_mode_status
;
};
};
/// The global TextIOHandler object
/// The global TextIOHandler object
...
...
src/main.cpp
View file @
b4a2a1a8
...
@@ -191,9 +191,18 @@ int MSE::OnRun() {
...
@@ -191,9 +191,18 @@ int MSE::OnRun() {
cli
<<
_
(
"
\n
\t
IMAGE is the same format as for 'export all card images'."
);
cli
<<
_
(
"
\n
\t
IMAGE is the same format as for 'export all card images'."
);
cli
<<
_
(
"
\n\n
"
)
<<
BRIGHT
<<
_
(
"--cli"
)
<<
NORMAL
<<
_
(
" ["
)
cli
<<
_
(
"
\n\n
"
)
<<
BRIGHT
<<
_
(
"--cli"
)
<<
NORMAL
<<
_
(
" ["
)
<<
PARAM
<<
_
(
"FILE"
)
<<
NORMAL
<<
_
(
"] ["
)
<<
PARAM
<<
_
(
"FILE"
)
<<
NORMAL
<<
_
(
"] ["
)
<<
BRIGHT
<<
_
(
"--quiet"
)
<<
NORMAL
<<
_
(
"]"
);
<<
BRIGHT
<<
_
(
"--quiet"
)
<<
NORMAL
<<
_
(
"] ["
)
<<
BRIGHT
<<
_
(
"--raw"
)
<<
NORMAL
<<
_
(
"]"
);
cli
<<
_
(
"
\n
\t
Start the command line interface for performing commands on the set file."
);
cli
<<
_
(
"
\n
\t
Start the command line interface for performing commands on the set file."
);
cli
<<
_
(
"
\n
\t
Use "
)
<<
BRIGHT
<<
_
(
"-q"
)
<<
NORMAL
<<
_
(
" or "
)
<<
BRIGHT
<<
_
(
"--quiet"
)
<<
NORMAL
<<
_
(
" to supress the startup banner and prompts."
);
cli
<<
_
(
"
\n
\t
Use "
)
<<
BRIGHT
<<
_
(
"-q"
)
<<
NORMAL
<<
_
(
" or "
)
<<
BRIGHT
<<
_
(
"--quiet"
)
<<
NORMAL
<<
_
(
" to supress the startup banner and prompts."
);
cli
<<
_
(
"
\n
\t
Use "
)
<<
BRIGHT
<<
_
(
"-raw"
)
<<
NORMAL
<<
_
(
" for raw output mode."
);
cli
<<
_
(
"
\n\n
Raw output mode is intended for use by other programs:"
);
cli
<<
_
(
"
\n
- The only output is only in response to commands."
);
cli
<<
_
(
"
\n
- For each command a single 'record' is written to the standard output."
);
cli
<<
_
(
"
\n
- The record consists of:"
);
cli
<<
_
(
"
\n
- A line with an integer status code, 0 for ok, 1 for warnings, 2 for errors"
);
cli
<<
_
(
"
\n
- A line containing an integer k, the number of lines to follow"
);
cli
<<
_
(
"
\n
- k lines, each containing UTF-8 encoded string data."
);
cli
<<
ENDL
;
cli
<<
ENDL
;
cli
.
flush
();
cli
.
flush
();
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
...
@@ -214,6 +223,9 @@ int MSE::OnRun() {
...
@@ -214,6 +223,9 @@ int MSE::OnRun() {
set
=
import_set
(
arg
);
set
=
import_set
(
arg
);
}
else
if
(
arg
==
_
(
"-q"
)
||
arg
==
_
(
"--quiet"
))
{
}
else
if
(
arg
==
_
(
"-q"
)
||
arg
==
_
(
"--quiet"
))
{
quiet
=
true
;
quiet
=
true
;
}
else
if
(
arg
==
_
(
"-r"
)
||
arg
==
_
(
"--raw"
))
{
quiet
=
true
;
cli
.
enableRaw
();
}
}
}
}
CLISetInterface
cli_interface
(
set
,
quiet
);
CLISetInterface
cli_interface
(
set
,
quiet
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment