15ffd83dbSDimitry Andric //===-- CommandObjectGUI.cpp ----------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "CommandObjectGUI.h"
10*0b57cec5SDimitry Andric 
11480093f4SDimitry Andric #include "lldb/Core/IOHandlerCursesGUI.h"
12480093f4SDimitry Andric #include "lldb/Host/Config.h"
13*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
14*0b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric using namespace lldb;
17*0b57cec5SDimitry Andric using namespace lldb_private;
18*0b57cec5SDimitry Andric 
19*0b57cec5SDimitry Andric // CommandObjectGUI
20*0b57cec5SDimitry Andric 
21*0b57cec5SDimitry Andric CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
22*0b57cec5SDimitry Andric     : CommandObjectParsed(interpreter, "gui",
23*0b57cec5SDimitry Andric                           "Switch into the curses based GUI mode.", "gui") {}
24*0b57cec5SDimitry Andric 
25*0b57cec5SDimitry Andric CommandObjectGUI::~CommandObjectGUI() {}
26*0b57cec5SDimitry Andric 
27*0b57cec5SDimitry Andric bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
28480093f4SDimitry Andric #if LLDB_ENABLE_CURSES
29*0b57cec5SDimitry Andric   if (args.GetArgumentCount() == 0) {
30*0b57cec5SDimitry Andric     Debugger &debugger = GetDebugger();
31*0b57cec5SDimitry Andric 
329dba64beSDimitry Andric     File &input = debugger.GetInputFile();
339dba64beSDimitry Andric     File &output = debugger.GetOutputFile();
349dba64beSDimitry Andric     if (input.GetStream() && output.GetStream() && input.GetIsRealTerminal() &&
359dba64beSDimitry Andric         input.GetIsInteractive()) {
36*0b57cec5SDimitry Andric       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
37*0b57cec5SDimitry Andric       if (io_handler_sp)
385ffd83dbSDimitry Andric         debugger.RunIOHandlerAsync(io_handler_sp);
39*0b57cec5SDimitry Andric       result.SetStatus(eReturnStatusSuccessFinishResult);
40*0b57cec5SDimitry Andric     } else {
41*0b57cec5SDimitry Andric       result.AppendError("the gui command requires an interactive terminal.");
42*0b57cec5SDimitry Andric       result.SetStatus(eReturnStatusFailed);
43*0b57cec5SDimitry Andric     }
44*0b57cec5SDimitry Andric   } else {
45*0b57cec5SDimitry Andric     result.AppendError("the gui command takes no arguments.");
46*0b57cec5SDimitry Andric     result.SetStatus(eReturnStatusFailed);
47*0b57cec5SDimitry Andric   }
48*0b57cec5SDimitry Andric   return true;
49*0b57cec5SDimitry Andric #else
505ffd83dbSDimitry Andric   result.AppendError("lldb was not built with gui support");
51*0b57cec5SDimitry Andric   return false;
52*0b57cec5SDimitry Andric #endif
53*0b57cec5SDimitry Andric }
54