1dda28197Spatrick //===-- CommandObjectGUI.cpp ----------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "CommandObjectGUI.h"
10061da546Spatrick 
11061da546Spatrick #include "lldb/Core/IOHandlerCursesGUI.h"
12061da546Spatrick #include "lldb/Host/Config.h"
13061da546Spatrick #include "lldb/Interpreter/CommandInterpreter.h"
14061da546Spatrick #include "lldb/Interpreter/CommandReturnObject.h"
15061da546Spatrick 
16061da546Spatrick using namespace lldb;
17061da546Spatrick using namespace lldb_private;
18061da546Spatrick 
19061da546Spatrick // CommandObjectGUI
20061da546Spatrick 
CommandObjectGUI(CommandInterpreter & interpreter)21061da546Spatrick CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
22061da546Spatrick     : CommandObjectParsed(interpreter, "gui",
23061da546Spatrick                           "Switch into the curses based GUI mode.", "gui") {}
24061da546Spatrick 
25*be691f3bSpatrick CommandObjectGUI::~CommandObjectGUI() = default;
26061da546Spatrick 
DoExecute(Args & args,CommandReturnObject & result)27061da546Spatrick bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
28061da546Spatrick #if LLDB_ENABLE_CURSES
29061da546Spatrick   Debugger &debugger = GetDebugger();
30061da546Spatrick 
31061da546Spatrick   File &input = debugger.GetInputFile();
32061da546Spatrick   File &output = debugger.GetOutputFile();
33061da546Spatrick   if (input.GetStream() && output.GetStream() && input.GetIsRealTerminal() &&
34061da546Spatrick       input.GetIsInteractive()) {
35061da546Spatrick     IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
36061da546Spatrick     if (io_handler_sp)
37dda28197Spatrick       debugger.RunIOHandlerAsync(io_handler_sp);
38061da546Spatrick     result.SetStatus(eReturnStatusSuccessFinishResult);
39061da546Spatrick   } else {
40061da546Spatrick     result.AppendError("the gui command requires an interactive terminal.");
41061da546Spatrick   }
42061da546Spatrick   return true;
43061da546Spatrick #else
44dda28197Spatrick   result.AppendError("lldb was not built with gui support");
45061da546Spatrick   return false;
46061da546Spatrick #endif
47061da546Spatrick }
48