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
edb7c6e6
Commit
edb7c6e6
authored
5 years ago
by
Ludovic Apvrille
Browse files
Options
Downloads
Patches
Plain Diff
Handling of up and down cursors in terminals
parent
142b48f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/myutil/Terminal.java
+72
-4
72 additions, 4 deletions
src/main/java/myutil/Terminal.java
with
72 additions
and
4 deletions
src/main/java/myutil/Terminal.java
+
72
−
4
View file @
edb7c6e6
...
@@ -63,6 +63,8 @@ public class Terminal {
...
@@ -63,6 +63,8 @@ public class Terminal {
private
final
static
int
TAB
=
9
;
private
final
static
int
TAB
=
9
;
private
Vector
<
String
>
buffer
;
private
Vector
<
String
>
buffer
;
private
int
bufferPointer
;
private
int
promptLength
=
0
;
private
int
maxbufferSize
=
MAX_BUFFER_SIZE
;
private
int
maxbufferSize
=
MAX_BUFFER_SIZE
;
private
TerminalProviderInterface
terminalProvider
;
private
TerminalProviderInterface
terminalProvider
;
private
int
cpt
;
private
int
cpt
;
...
@@ -114,17 +116,53 @@ public class Terminal {
...
@@ -114,17 +116,53 @@ public class Terminal {
}
}
}
}
/*if (sequence != null) {
TraceManager.addDev("Sequence=" + sequence);
printSequence(sequence);
}*/
if
((
sequence
!=
null
)
&&
(
sequence
.
length
()
==
2
))
{
//UP?
if
((
sequence
.
charAt
(
0
)
==
91
)
&&
(
sequence
.
charAt
(
1
)
==
65
))
{
//System.out.println("UP");
delCurrent
(
currentBuf
);
bufferPointer
=
(
bufferPointer
>
0
)?
bufferPointer
-
1
:
bufferPointer
;
currentBuf
=
buffer
.
get
(
bufferPointer
);
//printPrompt(cpt);
myPrint
(
currentBuf
);
sequence
=
null
;
val
=
-
1
;
// DOWN?
}
else
if
((
sequence
.
charAt
(
0
)
==
91
)
&&
(
sequence
.
charAt
(
1
)
==
66
))
{
//System.out.println("DOWN");
delCurrent
(
currentBuf
);
bufferPointer
=
(
bufferPointer
==(
buffer
.
size
()-
1
))?
bufferPointer:
bufferPointer
+
1
;
currentBuf
=
buffer
.
get
(
bufferPointer
);
//printPrompt(cpt);
myPrint
(
currentBuf
);
sequence
=
null
;
val
=
-
1
;
// DEL
//TraceManager.addDev("DEL");
}
}
if
((
sequence
!=
null
)
&&
(
sequence
.
length
()
==
3
))
{
if
((
sequence
!=
null
)
&&
(
sequence
.
length
()
==
3
))
{
//TraceManager.addDev("Sequence=" + sequence);
//
printSequence(sequence);
//
DEL
if
((
sequence
.
charAt
(
0
)
==
91
)
&&
(
sequence
.
charAt
(
1
)
==
51
)
&&
if
((
sequence
.
charAt
(
0
)
==
91
)
&&
(
sequence
.
charAt
(
1
)
==
51
)
&&
(
sequence
.
charAt
(
2
)
==
126
))
{
(
sequence
.
charAt
(
2
)
==
126
))
{
currentBuf
=
del
(
currentBuf
);
currentBuf
=
del
(
currentBuf
);
sequence
=
null
;
sequence
=
null
;
val
=
-
1
;
val
=
-
1
;
// DEL
//TraceManager.addDev("DEL");
//TraceManager.addDev("DEL");
}
}
}
else
if
((
sequence
!=
null
)
&&
(
sequence
.
length
()
>
4
))
{
}
else
if
((
sequence
!=
null
)
&&
(
sequence
.
length
()
>
4
))
{
}
}
...
@@ -138,6 +176,7 @@ public class Terminal {
...
@@ -138,6 +176,7 @@ public class Terminal {
}
else
{
}
else
{
cpt
++;
cpt
++;
//myPrint("\n");
//myPrint("\n");
addToBuffer
(
currentBuf
);
return
currentBuf
;
return
currentBuf
;
}
}
}
}
...
@@ -145,6 +184,7 @@ public class Terminal {
...
@@ -145,6 +184,7 @@ public class Terminal {
//BACKSPACE
//BACKSPACE
if
((
val
==
BACKSPACE
)
||
(
val
==
DEL
))
{
if
((
val
==
BACKSPACE
)
||
(
val
==
DEL
))
{
currentBuf
=
del
(
currentBuf
);
currentBuf
=
del
(
currentBuf
);
//TAB
//TAB
}
else
if
(
val
==
TAB
)
{
}
else
if
(
val
==
TAB
)
{
System
.
out
.
println
(
"TAB"
);
System
.
out
.
println
(
"TAB"
);
...
@@ -171,6 +211,23 @@ public class Terminal {
...
@@ -171,6 +211,23 @@ public class Terminal {
return
""
;
return
""
;
}
}
private
void
addToBuffer
(
String
newBuf
)
{
// Add at bufferPointer
// Therefore remove all elements after bufferPointer
for
(
int
i
=
buffer
.
size
()-
1
;
i
>=
bufferPointer
;
i
--)
{
buffer
.
removeElementAt
(
i
);
}
buffer
.
add
(
newBuf
);
if
(
buffer
.
size
()
>
maxbufferSize
)
{
buffer
.
removeElementAt
(
0
);
}
bufferPointer
=
buffer
.
size
();
}
private
String
del
(
String
currentBuf
)
{
private
String
del
(
String
currentBuf
)
{
if
(
currentBuf
.
length
()
>
0
)
{
if
(
currentBuf
.
length
()
>
0
)
{
...
@@ -203,11 +260,22 @@ public class Terminal {
...
@@ -203,11 +260,22 @@ public class Terminal {
}
}
private
String
delCurrent
(
String
currentBuf
)
{
if
(
buffer
.
size
()
>
0
)
{
int
size
=
currentBuf
.
length
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
currentBuf
=
del
(
currentBuf
);
}
}
return
currentBuf
;
}
public
void
printPrompt
(
int
cpt
)
{
public
void
printPrompt
(
int
cpt
)
{
System
.
out
.
print
(
""
+
cpt
+
"> "
);
String
p
=
""
+
cpt
+
"> "
;
promptLength
=
p
.
length
();
System
.
out
.
print
(
p
);
}
}
...
...
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