blob: 94b811cbc6d55782bffd5bc5517987dc0269651c [file] [log] [blame]
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <termios.h>
#include <base/files/scoped_file.h>
#include <base/macros.h>
namespace vm_tools {
namespace vsh {
// ScopedTermios is a helper class for managing termios settings,
// namely raw/canonical mode. When an instance of this class goes
// out of scope, it will restore the original termios settings.
class ScopedTermios {
// Creates an instance of ScopedTermios that will control the termios
// settings for a TTY. The TTY fd must be valid for at least the lifetime of
// this ScopedTermios instance.
explicit ScopedTermios(base::ScopedFD tty_fd);
ScopedTermios(const ScopedTermios&) = delete;
ScopedTermios& operator=(const ScopedTermios&) = delete;
enum class TermiosMode { RAW, CANON };
// Sets the termios mode for the TTY.
bool SetTermiosMode(TermiosMode mode);
// Restores the termios settings for the TTY to match those before
// SetTermiosMode was first called.
bool Restore();
// Gets the raw FD for this terminal.
int GetRawFD();
base::ScopedFD tty_fd_;
bool has_termios_;
struct termios saved_termios_;
} // namespace vsh
} // namespace vm_tools