1 //===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "CommandObjectGUI.h"
11 
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandReturnObject.h"
14 #include "lldb/lldb-private.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 //-------------------------------------------------------------------------
20 // CommandObjectGUI
21 //-------------------------------------------------------------------------
22 
CommandObjectGUI(CommandInterpreter & interpreter)23 CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
24     : CommandObjectParsed(interpreter, "gui",
25                           "Switch into the curses based GUI mode.", "gui") {}
26 
~CommandObjectGUI()27 CommandObjectGUI::~CommandObjectGUI() {}
28 
DoExecute(Args & args,CommandReturnObject & result)29 bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
30 #ifndef LLDB_DISABLE_CURSES
31   if (args.GetArgumentCount() == 0) {
32     Debugger &debugger = m_interpreter.GetDebugger();
33 
34     lldb::StreamFileSP input_sp = debugger.GetInputFile();
35     if (input_sp && input_sp->GetFile().GetIsRealTerminal() &&
36         input_sp->GetFile().GetIsInteractive()) {
37       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
38       if (io_handler_sp)
39         debugger.PushIOHandler(io_handler_sp);
40       result.SetStatus(eReturnStatusSuccessFinishResult);
41     } else {
42       result.AppendError("the gui command requires an interactive terminal.");
43       result.SetStatus(eReturnStatusFailed);
44     }
45   } else {
46     result.AppendError("the gui command takes no arguments.");
47     result.SetStatus(eReturnStatusFailed);
48   }
49   return true;
50 #else
51   result.AppendError("lldb was not build with gui support");
52   return false;
53 #endif
54 }
55