Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
mbe-tools
TTool
Commits
a7ff9c2b
Commit
a7ff9c2b
authored
5 years ago
by
Ludovic Apvrille
Browse files
Options
Downloads
Patches
Plain Diff
Update on history command
parent
70060a9e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/main/java/cli/History.java
+19
-4
19 additions, 4 deletions
src/main/java/cli/History.java
src/main/java/cli/Interpreter.java
+20
-6
20 additions, 6 deletions
src/main/java/cli/Interpreter.java
src/main/java/myutil/Terminal.java
+7
-18
7 additions, 18 deletions
src/main/java/myutil/Terminal.java
with
46 additions
and
28 deletions
src/main/java/cli/History.java
+
19
−
4
View file @
a7ff9c2b
...
@@ -76,16 +76,31 @@ public class History extends Command {
...
@@ -76,16 +76,31 @@ public class History extends Command {
return
"hi"
;
return
"hi"
;
}
}
public
String
getUsage
()
{
return
"history"
;
}
public
String
getUsage
()
{
return
"history
[command id (optional)]
"
;
}
public
String
getDescription
()
{
public
String
getDescription
()
{
return
"Prints all the non empty commands previously executed"
;
return
"Prints all the non empty commands previously executed\n"
+
" If an int arg is povided, the corresponding command is executed"
;
}
}
public
String
executeCommand
(
String
command
,
Interpreter
interpreter
)
{
public
String
executeCommand
(
String
command
,
Interpreter
interpreter
)
{
TraceManager
.
addDev
(
"History command"
);
//TraceManager.addDev("History command:" + command);
return
interpreter
.
printAllFormerCommands
();
if
(
command
.
length
()
==
0
)
{
return
interpreter
.
printAllFormerCommands
();
}
try
{
Integer
indexInfo
=
new
Integer
(
command
);
return
interpreter
.
executeFormerCommand
(
indexInfo
);
}
catch
(
Exception
e
)
{
return
"Invalid argument. Must provide an int"
;
}
}
}
public
void
fillSubCommands
()
{
public
void
fillSubCommands
()
{
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cli/Interpreter.java
+
20
−
6
View file @
a7ff9c2b
...
@@ -87,6 +87,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
...
@@ -87,6 +87,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
public
MainGUI
mgui
;
public
MainGUI
mgui
;
private
Vector
<
String
>
formerCommands
;
private
Vector
<
String
>
formerCommands
;
private
Terminal
term
;
private
Terminal
term
;
private
int
currentLine
;
public
Interpreter
(
String
script
,
InterpreterOutputInterface
printInterface
,
boolean
show
)
{
public
Interpreter
(
String
script
,
InterpreterOutputInterface
printInterface
,
boolean
show
)
{
...
@@ -108,10 +109,10 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
...
@@ -108,10 +109,10 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
term
.
setTerminalProvider
(
this
);
term
.
setTerminalProvider
(
this
);
String
line
;
String
line
;
int
cp
tLine
=
0
;
curren
tLine
=
0
;
while
((
line
=
term
.
getNextCommand
())
!=
null
)
{
while
((
line
=
term
.
getNextCommand
())
!=
null
)
{
executeLine
(
line
,
c
p
tLine
,
false
);
executeLine
(
line
,
c
urren
tLine
,
false
);
c
p
tLine
++;
c
urren
tLine
++;
}
}
}
}
...
@@ -140,11 +141,11 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
...
@@ -140,11 +141,11 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
public
void
interpret
()
{
public
void
interpret
()
{
Scanner
scanner
=
new
Scanner
(
script
);
Scanner
scanner
=
new
Scanner
(
script
);
int
cp
tLine
=
0
;
curren
tLine
=
0
;
while
(
scanner
.
hasNextLine
())
{
while
(
scanner
.
hasNextLine
())
{
String
line
=
scanner
.
nextLine
();
String
line
=
scanner
.
nextLine
();
c
p
tLine
++;
c
urren
tLine
++;
executeLine
(
line
,
c
p
tLine
,
true
);
executeLine
(
line
,
c
urren
tLine
,
true
);
}
}
scanner
.
close
();
scanner
.
close
();
...
@@ -302,6 +303,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
...
@@ -302,6 +303,7 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
printInterface
.
print
(
s
);
printInterface
.
print
(
s
);
}
}
// History
public
String
printAllFormerCommands
()
{
public
String
printAllFormerCommands
()
{
StringBuffer
sb
=
new
StringBuffer
(
""
);
StringBuffer
sb
=
new
StringBuffer
(
""
);
for
(
int
i
=
0
;
i
<
formerCommands
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
formerCommands
.
size
();
i
++)
{
...
@@ -311,6 +313,18 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
...
@@ -311,6 +313,18 @@ public class Interpreter implements Runnable, TerminalProviderInterface {
return
null
;
return
null
;
}
}
public
String
executeFormerCommand
(
int
indexOfCommand
)
{
if
(
indexOfCommand
>=
formerCommands
.
size
()
||
(
indexOfCommand
<
0
))
{
return
"Invalid command index"
;
}
String
formerCommand
=
formerCommands
.
get
(
indexOfCommand
);
System
.
out
.
println
(
"Executing: "
+
formerCommand
);
executeLine
(
formerCommand
,
currentLine
,
false
);
return
null
;
}
// Terminal provider interface
// Terminal provider interface
public
String
getMidPrompt
()
{
public
String
getMidPrompt
()
{
return
"> "
;
return
"> "
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/myutil/Terminal.java
+
7
−
18
View file @
a7ff9c2b
...
@@ -189,6 +189,8 @@ public class Terminal {
...
@@ -189,6 +189,8 @@ public class Terminal {
// Usual CHAR
// Usual CHAR
if
((
sequence
==
null
)
&&
(
val
!=
-
1
))
{
if
((
sequence
==
null
)
&&
(
val
!=
-
1
))
{
// CR
if
(
val
==
CR
)
{
if
(
val
==
CR
)
{
cursorPosition
=
0
;
cursorPosition
=
0
;
if
(
currentBuf
.
length
()
==
0
)
{
if
(
currentBuf
.
length
()
==
0
)
{
...
@@ -196,9 +198,10 @@ public class Terminal {
...
@@ -196,9 +198,10 @@ public class Terminal {
printPrompt
(
cpt
);
printPrompt
(
cpt
);
}
else
{
}
else
{
cpt
++;
cpt
++;
if
(!(
os
.
startsWith
(
"mac"
)))
{
//if (!(os.startsWith("mac"))) {
myPrint
(
"\n"
);
myPrint
(
"\n"
);
}
//
}
addToBuffer
(
currentBuf
);
addToBuffer
(
currentBuf
);
return
currentBuf
;
return
currentBuf
;
}
}
...
@@ -225,7 +228,7 @@ public class Terminal {
...
@@ -225,7 +228,7 @@ public class Terminal {
myPrint
(
""
+
x
);
myPrint
(
""
+
x
);
currentBuf
+=
x
;
currentBuf
+=
x
;
}
else
{
}
else
{
currentBuf
=
currentBuf
.
substring
(
0
,
cursorPosition
)
+
x
+
currentBuf
.
substring
(
cursorPosition
,
currentBuf
.
length
());
currentBuf
=
currentBuf
.
substring
(
0
,
cursorPosition
-
1
)
+
x
+
currentBuf
.
substring
(
cursorPosition
,
currentBuf
.
length
());
myPrint
(
""
+
x
+
currentBuf
.
substring
(
cursorPosition
,
currentBuf
.
length
()));
myPrint
(
""
+
x
+
currentBuf
.
substring
(
cursorPosition
,
currentBuf
.
length
()));
}
}
cursorPosition
++;
cursorPosition
++;
...
@@ -272,23 +275,9 @@ public class Terminal {
...
@@ -272,23 +275,9 @@ public class Terminal {
//if (os.compareTo("mac") != 0) {
//if (os.compareTo("mac") != 0) {
System
.
out
.
print
(
s
);
System
.
out
.
print
(
s
);
//}
//}
//System.out.flush();
System
.
out
.
flush
();
}
public
void
printHistory
()
{
int
cpt
=
1
;
for
(
String
s:
buffer
)
{
System
.
out
.
println
(
""
+
cpt
+
":"
+
s
);
cpt
++;
}
}
}
private
void
printSequence
(
String
seq
)
{
for
(
int
i
=
0
;
i
<
seq
.
length
();
i
++)
{
System
.
out
.
print
(
""
+
(
int
)(
seq
.
charAt
(
i
))
+
" "
);
}
System
.
out
.
println
(
""
);
}
private
String
delCurrent
(
String
currentBuf
)
{
private
String
delCurrent
(
String
currentBuf
)
{
...
...
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