Skip to content

Commit 2c5efbd

Browse files
authored
Merge pull request #368 from yamacir-kit/iostream
Iostream
2 parents 1b35416 + cf176db commit 2c5efbd

31 files changed

+213
-218
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ sudo rm -rf /usr/local/share/meevax
100100

101101
| Target Name | Description
102102
|:-------------------|:--
103-
| `all` (default) | Build shared-library `libmeevax.0.3.773.so` and executable `meevax`.
103+
| `all` (default) | Build shared-library `libmeevax.0.3.783.so` and executable `meevax`.
104104
| `test` | Test executable `meevax`.
105-
| `package` | Generate debian package `meevax_0.3.773_amd64.deb`.
105+
| `package` | Generate debian package `meevax_0.3.783_amd64.deb`.
106106
| `install` | Copy files into `/usr/local` __(1)__.
107107
| `install.deb` | `all` + `package` + `sudo apt install <meevax>.deb`
108108
| `safe-install.deb` | `all` + `test` + `package` + `sudo apt install <meevax>.deb`
@@ -117,7 +117,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's
117117
## Usage
118118

119119
```
120-
Meevax Lisp System, version 0.3.773
120+
Meevax Lisp System, version 0.3.783
121121
122122
Usage: meevax [OPTION...] [FILE...]
123123

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.773
1+
0.3.783
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright 2018-2021 Tatsuya Yamasaki.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef INCLUDED_MEEVAX_IOSTREAM_ESCAPE_SEQUENCE_HPP
18+
#define INCLUDED_MEEVAX_IOSTREAM_ESCAPE_SEQUENCE_HPP
19+
20+
#include <tuple>
21+
22+
#include <meevax/iostream/is_console.hpp>
23+
#include <meevax/utility/unwrap_reference_wrapper.hpp>
24+
25+
namespace meevax
26+
{
27+
inline namespace iostream
28+
{
29+
template <typename... Ts>
30+
struct escape_sequence
31+
{
32+
char const* command;
33+
34+
std::tuple<
35+
typename std::conditional<
36+
not std::is_reference<Ts>::value or std::is_scalar<typename std::remove_reference<Ts>::type>::value,
37+
typename std::decay<Ts>::type,
38+
std::reference_wrapper<typename std::remove_reference<Ts>::type>
39+
>::type...
40+
> references;
41+
42+
template <typename T>
43+
explicit constexpr escape_sequence(T&& x, Ts&&... xs)
44+
: command { std::forward<decltype(x)>(x) }
45+
, references { std::forward<decltype(xs)>(xs)... }
46+
{}
47+
48+
friend auto operator <<(std::ostream & os, escape_sequence const& sequence) -> std::ostream &
49+
{
50+
auto print = [&](auto&& ... xs) -> std::ostream &
51+
{
52+
return (os << ... << unwrap_reference_wrapper(xs));
53+
};
54+
55+
if (is_console(os))
56+
{
57+
os << "\x1b[" << sequence.command;
58+
std::apply(print, sequence.references);
59+
return os << "\x1b[0m";
60+
}
61+
else
62+
{
63+
std::apply(print, sequence.references);
64+
return os;
65+
}
66+
}
67+
};
68+
69+
template <typename T, typename... Ts>
70+
escape_sequence(T&&, Ts&&...) -> escape_sequence<Ts...>;
71+
72+
#define DEFINE(COMMAND, NAME) \
73+
auto NAME = [](auto&&... xs) \
74+
{ \
75+
return escape_sequence(COMMAND, std::forward<decltype(xs)>(xs)...); \
76+
}
77+
78+
DEFINE("1m", bold);
79+
DEFINE("2m", faint);
80+
DEFINE("3m", italic); // Not widely supported. Sometimes treated as inverse.
81+
DEFINE("4m", underline);
82+
DEFINE("5m", slow_blink); // Less than 150 per minite.
83+
DEFINE("6m", rapid_blink); // More than 150 per minite. Not widely supported.
84+
DEFINE("7m", reverse);
85+
DEFINE("8m", conceal); // Not widely supported.
86+
87+
inline namespace foreground
88+
{
89+
DEFINE("30m", black);
90+
DEFINE("31m", red);
91+
DEFINE("32m", green);
92+
DEFINE("33m", yellow);
93+
DEFINE("34m", blue);
94+
DEFINE("35m", magenta);
95+
DEFINE("36m", cyan);
96+
DEFINE("37m", white);
97+
}
98+
99+
namespace background
100+
{
101+
DEFINE("40m", black);
102+
DEFINE("41m", red);
103+
DEFINE("42m", green);
104+
DEFINE("43m", yellow);
105+
DEFINE("44m", blue);
106+
DEFINE("45m", magenta);
107+
DEFINE("46m", cyan);
108+
DEFINE("47m", white);
109+
}
110+
111+
#undef DEFINE
112+
} // namespace iostream
113+
} // namespace meevax
114+
115+
#endif // INCLUDED_MEEVAX_IOSTREAM_ESCAPE_SEQUENCE_HPP

include/meevax/posix/is_tty.hpp include/meevax/iostream/is_console.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
limitations under the License.
1515
*/
1616

17-
#ifndef INCLUDED_MEEVAX_POSIX_IS_TTY_HPP
18-
#define INCLUDED_MEEVAX_POSIX_IS_TTY_HPP
17+
#ifndef INCLUDED_MEEVAX_IOSTREAM_IS_CONSOLE_HPP
18+
#define INCLUDED_MEEVAX_IOSTREAM_IS_CONSOLE_HPP
1919

2020
#include <iostream>
2121

2222
#include <unistd.h>
2323

2424
namespace meevax
2525
{
26-
inline namespace posix
26+
inline namespace iostream
2727
{
28-
auto is_tty = [](std::ostream& os)
28+
auto is_console = [](std::ostream & os)
2929
{
3030
if (os.rdbuf() == std::cout.rdbuf())
3131
{
32-
static const auto result { static_cast<bool>(::isatty(STDOUT_FILENO)) };
32+
static auto const result = static_cast<bool>(::isatty(STDOUT_FILENO));
3333
return result;
3434
}
3535
else if (os.rdbuf() == std::cerr.rdbuf())
3636
{
37-
static const auto result { static_cast<bool>(::isatty(STDERR_FILENO)) };
37+
static auto const result = static_cast<bool>(::isatty(STDERR_FILENO));
3838
return result;
3939
}
4040
else
4141
{
4242
return false;
4343
}
4444
};
45-
} // namespace posix
45+
} // namespace iostream
4646
} // namespace meevax
4747

48-
#endif // INCLUDED_MEEVAX_POSIX_IS_TTY_HPP
48+
#endif // INCLUDED_MEEVAX_IOSTREAM_IS_CONSOLE_HPP

include/meevax/kernel/floating_point.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@ inline namespace kernel
160160
{
161161
if (std::isnan(rhs))
162162
{
163-
return os << cyan << "+nan.0" << reset;
163+
return os << cyan("+nan.0");
164164
}
165165
else if (std::isinf(rhs))
166166
{
167-
return os << cyan << (0 < rhs.value ? '+' : '-') << "inf.0" << reset;
167+
return os << cyan(0 < rhs.value ? '+' : '-', "inf.0");
168168
}
169169
else
170170
{
171-
return os << cyan << std::fixed << rhs.value << reset;
171+
return os << cyan(std::fixed, rhs.value);
172172
}
173173
}
174174
} // namespace kernel

include/meevax/kernel/heterogeneous.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#define INCLUDED_MEEVAX_KERNEL_POINTER_HPP
1919

2020
#include <meevax/functional/compose.hpp>
21+
#include <meevax/iostream/escape_sequence.hpp>
2122
#include <meevax/iostream/write.hpp>
2223
#include <meevax/kernel/profiler.hpp>
23-
#include <meevax/posix/vt10x.hpp>
2424
#include <meevax/type_traits/delay.hpp>
2525
#include <meevax/type_traits/is_equality_comparable.hpp>
2626
#include <meevax/utility/module.hpp>
@@ -148,7 +148,7 @@ inline namespace kernel
148148
template <template <typename...> typename Pointer, typename Top>
149149
auto operator <<(std::ostream & os, heterogeneous<Pointer, Top> const& datum) -> std::ostream &
150150
{
151-
return (datum.template is<null>() ? os << magenta << "()" : datum->write(os)) << reset;
151+
return datum.template is<null>() ? os << magenta("()") : datum->write(os);
152152
}
153153
} // namespace kernel
154154
} // namespace meevax

include/meevax/kernel/machine.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ inline namespace kernel
119119

120120
friend auto operator <<(std::ostream & os, transformer const& datum) -> std::ostream &
121121
{
122-
return os << "#,(fork/csc " << datum.expression << ")";
122+
return os << magenta("#,(") << blue("fork/csc ") << datum.expression << magenta(")");
123123
}
124124
};
125125

@@ -276,10 +276,10 @@ inline namespace kernel
276276
decode:
277277
if constexpr (Option & option::trace)
278278
{
279-
std::cerr << faint << "; s = " << posix::reset << s << "\n"
280-
<< faint << "; e = " << posix::reset << e << "\n"
281-
<< faint << "; c = " << posix::reset << c << "\n"
282-
<< faint << "; d = " << posix::reset << d << "\n" << std::endl;
279+
std::cerr << faint("; s = ") << s << "\n"
280+
<< faint("; e = ") << e << "\n"
281+
<< faint("; c = ") << c << "\n"
282+
<< faint("; d = ") << d << "\n" << std::endl;
283283
}
284284

285285
switch (car(c).template as<instruction>().value)

include/meevax/kernel/writer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ inline namespace kernel
3939
template <typename... Ts>
4040
auto write(std::ostream & os, Ts&&... xs) const -> std::ostream &
4141
{
42-
return (os << ... << xs) << reset;
42+
return (os << ... << xs);
4343
}
4444

4545
template <typename... Ts>

include/meevax/posix/vt10x.hpp

-108
This file was deleted.

src/kernel/posix.cpp include/meevax/type_traits/is_reference_wrapper.hpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,25 @@
1414
limitations under the License.
1515
*/
1616

17-
#include <meevax/posix/vt10x.hpp>
17+
#ifndef INCLUDED_MEEVAX_TYPE_TRAITS_IS_REFERENCE_WRAPPER_HPP
18+
#define INCLUDED_MEEVAX_TYPE_TRAITS_IS_REFERENCE_WRAPPER_HPP
19+
20+
#include <type_traits>
1821

1922
namespace meevax
2023
{
21-
inline namespace posix
24+
inline namespace type_traits
2225
{
23-
auto operator <<(std::ostream& port, const cursor_move& datum) -> decltype(port)
24-
{
25-
return escape_sequence(port, datum.value, datum.code);
26-
}
27-
} // namespace posix
26+
template <typename T>
27+
struct is_reference_wrapper
28+
: public std::false_type
29+
{};
30+
31+
template <typename T>
32+
struct is_reference_wrapper<std::reference_wrapper<T>>
33+
: public std::true_type
34+
{};
35+
} // namespace type_traits
2836
} // namespace meevax
37+
38+
#endif // INCLUDED_MEEVAX_TYPE_TRAITS_IS_REFERENCE_WRAPPER_HPP

0 commit comments

Comments
 (0)