Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
orbutils
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
Container Registry
Model registry
Operate
Environments
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
Nick Thomas
orbutils
Commits
e07994ad
Commit
e07994ad
authored
8 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Correct usage of new psuedoterminals
parent
d097db7a
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/terminal/main.rs
+25
-39
25 additions, 39 deletions
src/terminal/main.rs
with
25 additions
and
39 deletions
src/terminal/main.rs
+
25
−
39
View file @
e07994ad
...
@@ -5,13 +5,14 @@ extern crate orbclient;
...
@@ -5,13 +5,14 @@ extern crate orbclient;
use
orbclient
::
event
;
use
orbclient
::
event
;
use
std
::
env
;
use
std
::
{
env
,
str
,
thread
}
;
use
std
::
error
::
Error
;
use
std
::
error
::
Error
;
use
std
::
fs
::
File
;
use
std
::
io
::{
Read
,
Write
,
self
};
use
std
::
io
::{
Read
,
Write
,
self
};
use
std
::
os
::
unix
::
io
::{
FromRawFd
,
IntoRawFd
};
use
std
::
process
::{
Command
,
Stdio
};
use
std
::
process
::{
Command
,
Stdio
};
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
time
::
Duration
;
use
std
::
time
::
Duration
;
use
std
::
thread
;
use
console
::
Console
;
use
console
::
Console
;
...
@@ -20,24 +21,41 @@ mod console;
...
@@ -20,24 +21,41 @@ mod console;
fn
main
()
{
fn
main
()
{
let
shell
=
env
::
args
()
.nth
(
1
)
.unwrap_or
(
"sh"
.to_string
());
let
shell
=
env
::
args
()
.nth
(
1
)
.unwrap_or
(
"sh"
.to_string
());
let
master
=
File
::
create
(
"pty:"
)
.unwrap
();
let
tty_path
=
master
.path
()
.unwrap
();
let
master_fd
=
master
.into_raw_fd
();
let
slave_stdin
=
File
::
open
(
&
tty_path
)
.unwrap
();
let
slave_stdout
=
File
::
open
(
&
tty_path
)
.unwrap
();
let
slave_stderr
=
File
::
open
(
&
tty_path
)
.unwrap
();
let
width
=
640
;
let
width
=
640
;
let
height
=
480
;
let
height
=
480
;
env
::
set_var
(
"COLUMNS"
,
format!
(
"{}"
,
width
/
8
));
env
::
set_var
(
"COLUMNS"
,
format!
(
"{}"
,
width
/
8
));
env
::
set_var
(
"LINES"
,
format!
(
"{}"
,
height
/
16
));
env
::
set_var
(
"LINES"
,
format!
(
"{}"
,
height
/
16
));
match
Command
::
new
(
&
shell
)
.stdin
(
Stdio
::
piped
())
.stdout
(
Stdio
::
piped
())
.stderr
(
Stdio
::
piped
())
.spawn
()
{
env
::
set_var
(
"TTY"
,
format!
(
"{}"
,
tty_path
.display
()));
Ok
(
process
)
=>
{
match
unsafe
{
Command
::
new
(
&
shell
)
.stdin
(
Stdio
::
from_raw_fd
(
slave_stdin
.into_raw_fd
()))
.stdout
(
Stdio
::
from_raw_fd
(
slave_stdout
.into_raw_fd
()))
.stderr
(
Stdio
::
from_raw_fd
(
slave_stderr
.into_raw_fd
()))
.spawn
()
}
{
Ok
(
_process
)
=>
{
let
output_mutex
=
Arc
::
new
(
Mutex
::
new
(
Some
(
Vec
::
new
())));
let
output_mutex
=
Arc
::
new
(
Mutex
::
new
(
Some
(
Vec
::
new
())));
let
mut
master_stdin
=
unsafe
{
File
::
from_raw_fd
(
master_fd
)
};
{
{
let
mut
stdout
=
process
.stdout
.unwrap
();
let
stdout_output_mutex
=
output_mutex
.clone
();
let
stdout_output_mutex
=
output_mutex
.clone
();
thread
::
spawn
(
move
||
{
thread
::
spawn
(
move
||
{
let
mut
master_stdout
=
unsafe
{
File
::
from_raw_fd
(
master_fd
)
};
let
term_stderr
=
io
::
stderr
();
let
term_stderr
=
io
::
stderr
();
let
mut
term_stderr
=
term_stderr
.lock
();
let
mut
term_stderr
=
term_stderr
.lock
();
'stdout
:
loop
{
'stdout
:
loop
{
let
mut
buf
=
[
0
;
4096
];
let
mut
buf
=
[
0
;
4096
];
match
stdout
.read
(
&
mut
buf
)
{
match
master_
stdout
.read
(
&
mut
buf
)
{
Ok
(
0
)
=>
break
'stdout
,
Ok
(
0
)
=>
break
'stdout
,
Ok
(
count
)
=>
match
stdout_output_mutex
.lock
()
{
Ok
(
count
)
=>
match
stdout_output_mutex
.lock
()
{
Ok
(
mut
stdout_output_option
)
=>
match
*
stdout_output_option
{
Ok
(
mut
stdout_output_option
)
=>
match
*
stdout_output_option
{
...
@@ -61,38 +79,6 @@ fn main() {
...
@@ -61,38 +79,6 @@ fn main() {
});
});
}
}
{
let
mut
stderr
=
process
.stderr
.unwrap
();
let
stderr_output_mutex
=
output_mutex
.clone
();
thread
::
spawn
(
move
||
{
let
mut
term_stderr
=
io
::
stderr
();
'stderr
:
loop
{
let
mut
buf
=
[
0
;
4096
];
match
stderr
.read
(
&
mut
buf
)
{
Ok
(
0
)
=>
break
'stderr
,
Ok
(
count
)
=>
match
stderr_output_mutex
.lock
()
{
Ok
(
mut
stderr_output_option
)
=>
match
*
stderr_output_option
{
Some
(
ref
mut
stderr_output
)
=>
stderr_output
.extend_from_slice
(
&
buf
[
..
count
]),
None
=>
break
'stderr
},
Err
(
_
)
=>
{
let
_
=
term_stderr
.write
(
b"failed to lock stdout output mutex
\n
"
);
break
'stderr
;
}
},
Err
(
err
)
=>
{
let
_
=
term_stderr
.write
(
b"failed to read stderr: "
);
let
_
=
term_stderr
.write
(
err
.description
()
.as_bytes
());
let
_
=
term_stderr
.write
(
b"
\n
"
);
break
'stderr
;
}
}
}
stderr_output_mutex
.lock
()
.unwrap
()
.take
();
});
}
let
mut
stdin
=
process
.stdin
.unwrap
();
let
mut
console
=
Console
::
new
(
width
,
height
);
let
mut
console
=
Console
::
new
(
width
,
height
);
'events
:
loop
{
'events
:
loop
{
match
output_mutex
.lock
()
{
match
output_mutex
.lock
()
{
...
@@ -117,7 +103,7 @@ fn main() {
...
@@ -117,7 +103,7 @@ fn main() {
}
}
if
let
Some
(
line
)
=
console
.event
(
event
)
{
if
let
Some
(
line
)
=
console
.event
(
event
)
{
if
let
Err
(
err
)
=
stdin
.write
(
&
line
.as_bytes
())
{
if
let
Err
(
err
)
=
master_
stdin
.write
(
&
line
.as_bytes
())
{
let
term_stderr
=
io
::
stderr
();
let
term_stderr
=
io
::
stderr
();
let
mut
term_stderr
=
term_stderr
.lock
();
let
mut
term_stderr
=
term_stderr
.lock
();
...
...
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