112b93ac6SEd Maste //===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
212b93ac6SEd Maste //
312b93ac6SEd Maste //                     The LLVM Compiler Infrastructure
412b93ac6SEd Maste //
512b93ac6SEd Maste // This file is distributed under the University of Illinois Open Source
612b93ac6SEd Maste // License. See LICENSE.TXT for details.
712b93ac6SEd Maste //
812b93ac6SEd Maste //===----------------------------------------------------------------------===//
912b93ac6SEd Maste 
1012b93ac6SEd Maste #include "CommandObjectGUI.h"
1112b93ac6SEd Maste 
1212b93ac6SEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
1312b93ac6SEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
14435933ddSDimitry Andric #include "lldb/lldb-private.h"
1512b93ac6SEd Maste 
1612b93ac6SEd Maste using namespace lldb;
1712b93ac6SEd Maste using namespace lldb_private;
1812b93ac6SEd Maste 
1912b93ac6SEd Maste //-------------------------------------------------------------------------
2012b93ac6SEd Maste // CommandObjectGUI
2112b93ac6SEd Maste //-------------------------------------------------------------------------
2212b93ac6SEd Maste 
CommandObjectGUI(CommandInterpreter & interpreter)23435933ddSDimitry Andric CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
24435933ddSDimitry Andric     : CommandObjectParsed(interpreter, "gui",
25435933ddSDimitry Andric                           "Switch into the curses based GUI mode.", "gui") {}
2612b93ac6SEd Maste 
~CommandObjectGUI()27435933ddSDimitry Andric CommandObjectGUI::~CommandObjectGUI() {}
2812b93ac6SEd Maste 
DoExecute(Args & args,CommandReturnObject & result)29435933ddSDimitry Andric bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
3012b93ac6SEd Maste #ifndef LLDB_DISABLE_CURSES
31435933ddSDimitry Andric   if (args.GetArgumentCount() == 0) {
3212b93ac6SEd Maste     Debugger &debugger = m_interpreter.GetDebugger();
331c3bbb01SEd Maste 
341c3bbb01SEd Maste     lldb::StreamFileSP input_sp = debugger.GetInputFile();
35435933ddSDimitry Andric     if (input_sp && input_sp->GetFile().GetIsRealTerminal() &&
36435933ddSDimitry Andric         input_sp->GetFile().GetIsInteractive()) {
3712b93ac6SEd Maste       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
3812b93ac6SEd Maste       if (io_handler_sp)
3912b93ac6SEd Maste         debugger.PushIOHandler(io_handler_sp);
4012b93ac6SEd Maste       result.SetStatus(eReturnStatusSuccessFinishResult);
41435933ddSDimitry Andric     } else {
421c3bbb01SEd Maste       result.AppendError("the gui command requires an interactive terminal.");
431c3bbb01SEd Maste       result.SetStatus(eReturnStatusFailed);
441c3bbb01SEd Maste     }
45435933ddSDimitry Andric   } else {
4612b93ac6SEd Maste     result.AppendError("the gui command takes no arguments.");
4712b93ac6SEd Maste     result.SetStatus(eReturnStatusFailed);
4812b93ac6SEd Maste   }
4912b93ac6SEd Maste   return true;
5012b93ac6SEd Maste #else
5112b93ac6SEd Maste   result.AppendError("lldb was not build with gui support");
5212b93ac6SEd Maste   return false;
5312b93ac6SEd Maste #endif
5412b93ac6SEd Maste }
55