terminalinputhandler.cc
来自「Linux下比较早的基于命令行的DVD播放器」· CC 代码 · 共 129 行
CC
129 行
//// Copyright (c) 2003 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//------------------------------------------------------------------------------#include "TerminalInputHandler.h"#include "util/POSIX.h"#include "util/Log.h"//------------------------------------------------------------------------------using input::CharInputHandler;using input::TerminalInputHandler;using input::InputListener;//------------------------------------------------------------------------------static CharInputHandler::Sequence terminalSequences[]={ { "8", 0, InputListener::UP }, // 8 { "\033[A", 0, InputListener::UP }, // Cursor Up { "2", 0, InputListener::DOWN }, // 2 { "\033[B", 0, InputListener::DOWN }, // Cursor Down { "4", 0, InputListener::LEFT }, // 4 { "\033[D", 0, InputListener::LEFT }, // Cursor Left { "6", 0, InputListener::RIGHT }, // 6 { "\033[C", 0, InputListener::RIGHT }, // Cursor Right { "5", 0, InputListener::ACTIVATE }, // 5 { "\r", 0, InputListener::ACTIVATE }, // Enter { "t", 0, InputListener::MENU_TITLE }, // t { "r", 0, InputListener::MENU_ROOT }, // r { "R", 0, InputListener::MENU_ROOT_FORCED }, // R { "s", 0, InputListener::MENU_SUBPICTURE }, // s { "a", 0, InputListener::MENU_AUDIO }, // a { "n", 0, InputListener::MENU_ANGLE }, // n { "p", 0, InputListener::MENU_PART }, // p { "P", 0, InputListener::PREVIOUS_CHAPTER }, // P { "\033[5~", 0, InputListener::PREVIOUS_CHAPTER }, // Page Up { "N", 0, InputListener::NEXT_CHAPTER }, // N { "\033[6~", 0, InputListener::NEXT_CHAPTER }, // Page Down { "1", 0, InputListener::PLAY }, // 1 { " ", 0, InputListener::PAUSE }, // Space { ">", 0, InputListener::PLAY_FAST_FORWARD }, // > { "<", 0, InputListener::PLAY_FAST_BACKWARD }, // < { "e", 0, InputListener::EJECT }, // e { "\033[4~", 0, InputListener::EJECT }, // End { "\033[8~", 0, InputListener::EJECT }, // End { "\033OF", 0, InputListener::EJECT }, // End { "\033[F", 0, InputListener::EJECT }, // End { "o", 0, InputListener::TOGGLE_OUTPUT }, // o { "y", 0, InputListener::RESYNCHRONIZE }, // y { "\033[1~", 0, InputListener::RESYNCHRONIZE }, // Home { "\033[7~", 0, InputListener::RESYNCHRONIZE }, // Home { "\033OH", 0, InputListener::RESYNCHRONIZE }, // Home { "\033[H", 0, InputListener::RESYNCHRONIZE }, // Home { "Y", 0, InputListener::RESYNCHRONIZE_ALL }, // Y { "v", 0, InputListener::VOLUME_RESET }, // v { "=", 0, InputListener::VOLUME_UP }, // = { "-", 0, InputListener::VOLUME_DOWN }, // - { "m", 0, InputListener::TOGGLE_AUDIO }, // m { "]", 0, InputListener::INCREASE_BRIGHTNESS }, // ] { "[", 0, InputListener::DECREASE_BRIGHTNESS }, // [ { "'", 0, InputListener::INCREASE_CONTRAST }, // ' { ";", 0, InputListener::DECREASE_CONTRAST }, // ; { "/", 0, InputListener::INCREASE_SATURATION }, // / { ".", 0, InputListener::DECREASE_SATURATION }, // . { "A", 0, InputListener::CHANGE_ANGLE }, // A { "L", 0, InputListener::NEXT_AUDIO_STREAM }, // L { "\033l", 0, InputListener::PREVIOUS_AUDIO_STREAM }, // Alt+l { "S", 0, InputListener::NEXT_SPU_STREAM }, // S { "\033s", 0, InputListener::PREVIOUS_SPU_STREAM }, // Alt+s { "i", 0, InputListener::PRINT_STATUS }, // i { "z", 0, InputListener::SAVE_DVD_STATE }, // z { "Z", 0, InputListener::RESUME_DVD_STATE }, // Z { "Q", 0, InputListener::QUIT }, // Q { 0, 0, InputListener::NONE }};//------------------------------------------------------------------------------TerminalInputHandler::TerminalInputHandler(InputListener& listener) : ReaderInputHandler(listener, "input::TerminalInputHandler", terminalSequences){ struct termios termios; int flags = POSIX::fcntl(0, F_GETFL); flags |= O_NONBLOCK; POSIX::fcntl(0, F_SETFL, flags); tcgetattr(0, &old_termios); tcgetattr(0, &termios); cfmakeraw(&termios); termios.c_oflag |= OPOST; tcsetattr(0, TCSANOW, &termios); start(0);} //------------------------------------------------------------------------------TerminalInputHandler::~TerminalInputHandler(){ Log::normal("input::TerminalInputHandler::~TerminalInputHandler: restoring terminal settings\n"); tcsetattr(0, TCSANOW, &old_termios);}//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?