mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::fs: Add experimental stdin::tty support.
This commit is contained in:
parent
2b654d13c5
commit
57bfe311c6
2 changed files with 40 additions and 0 deletions
|
@ -13,6 +13,23 @@
|
|||
|
||||
namespace ircd::fs::stdin
|
||||
{
|
||||
struct tty;
|
||||
|
||||
// Yields ircd::ctx to read line from stdin
|
||||
string_view readline(const mutable_buffer &);
|
||||
}
|
||||
|
||||
/// Directly represents the controlling tty of stdin if supported. The primary
|
||||
/// purpose here is to allow writing text to stdin to provide readline-esque
|
||||
/// history to the terminal console.
|
||||
///
|
||||
/// The member write() must be used, not fs::write(). The latter will throw
|
||||
/// an error when used on this.
|
||||
///
|
||||
struct ircd::fs::stdin::tty
|
||||
:fd
|
||||
{
|
||||
size_t write(const string_view &);
|
||||
|
||||
tty();
|
||||
};
|
||||
|
|
23
ircd/fs.cc
23
ircd/fs.cc
|
@ -109,6 +109,29 @@ ircd::fs::stdin::readline(const mutable_buffer &buf)
|
|||
};
|
||||
}
|
||||
|
||||
//
|
||||
// tty
|
||||
//
|
||||
|
||||
ircd::fs::stdin::tty::tty()
|
||||
:fd{[]
|
||||
{
|
||||
thread_local char buf[256];
|
||||
syscall(::ttyname_r, STDIN_FILENO, buf, sizeof(buf));
|
||||
return fd
|
||||
{
|
||||
string_view{buf}, std::ios_base::out
|
||||
};
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::fs::stdin::tty::write(const string_view &buf)
|
||||
{
|
||||
return syscall(::write, int(*this), buf.data(), buf.size());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// fs/read.h
|
||||
|
|
Loading…
Reference in a new issue