YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
Terminal.cpp
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3
* SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4
* SPDX-License-Identifier: BSD-3-Clause
5
*/
6
7
#include <
yarp/os/impl/Terminal.h
>
8
9
#include <
yarp/os/Bottle.h
>
10
#include <
yarp/os/Port.h
>
11
#include <
yarp/os/Vocab.h
>
12
#include <
yarp/os/impl/PlatformStdio.h
>
13
#include <
yarp/os/impl/PlatformUnistd.h
>
14
15
#include <cstdio>
16
#include <cstring>
17
18
#ifdef YARP_HAS_Libedit
19
# include <editline/readline.h>
20
char
* szLine = (
char
*)
nullptr
;
21
bool
readlineEOF =
false
;
22
#endif
// YARP_HAS_Libedit
23
24
bool
yarp::os::impl::Terminal::EOFreached
()
25
{
26
#ifdef YARP_HAS_Libedit
27
if
(yarp::os::impl::isatty(yarp::os::impl::fileno(
stdin
)) != 0) {
28
return
readlineEOF
;
29
}
30
#endif
// YARP_HAS_Libedit
31
return
feof
(
stdin
) != 0;
32
}
33
34
std::string
yarp::os::impl::Terminal::getStdin
()
35
{
36
std::string txt;
37
38
#ifdef YARP_HAS_Libedit
39
if
(yarp::os::impl::isatty(yarp::os::impl::fileno(
stdin
)) != 0) {
40
if
(
szLine
!=
nullptr
) {
41
free
(
szLine
);
42
szLine
= (
char
*)
nullptr
;
43
}
44
45
szLine
=
readline
(
">>"
);
46
if
((
szLine
!=
nullptr
) && (*
szLine
!= 0)) {
47
txt =
szLine
;
48
add_history
(
szLine
);
49
}
else
if
(
szLine
==
nullptr
) {
50
readlineEOF
=
true
;
51
}
52
return
txt;
53
}
54
#endif
// YARP_HAS_Libedit
55
56
bool
done =
false
;
57
char
buf[2048];
58
while
(!done) {
59
char
* result =
fgets
(buf,
sizeof
(buf),
stdin
);
60
if
(result !=
nullptr
) {
61
for
(
unsigned
int
i
= 0;
i
<
strlen
(buf);
i
++) {
62
if
(buf[
i
] ==
'\n'
) {
63
buf[
i
] =
'\0'
;
64
done =
true
;
65
break
;
66
}
67
}
68
txt += buf;
69
}
else
{
70
done =
true
;
71
}
72
}
73
return
txt;
74
}
75
76
std::string
yarp::os::impl::Terminal::readString
(
bool
*
eof
)
77
{
78
bool
end =
false
;
79
80
std::string txt;
81
if
(!
EOFreached
()) {
82
txt =
getStdin
();
83
}
84
85
if
(
EOFreached
() || (!txt.empty() && txt[0] < 32 && txt[0] !=
'\n'
&& txt[0] !=
'\r'
)) {
86
end =
true
;
87
}
88
89
if
(end) {
90
txt =
""
;
91
}
92
93
if
(
eof
!=
nullptr
) {
94
*
eof
= end;
95
}
96
return
txt;
97
}
Bottle.h
PlatformStdio.h
Port.h
Terminal.h
Vocab.h
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition
BufferedPort.h:60
PlatformUnistd.h
yarp::os::impl::Terminal::EOFreached
bool EOFreached()
Definition
Terminal.cpp:24
yarp::os::impl::Terminal::readString
std::string readString(bool *eof)
Definition
Terminal.cpp:76
yarp::os::impl::Terminal::getStdin
std::string getStdin()
Definition
Terminal.cpp:34
YARP
3.11.100+20250512.5+giteed569682
src
libYARP_os
src
yarp
os
impl
Terminal.cpp
Generated on Thu May 15 2025 02:40:14 for YARP by
1.9.8