144d93782SGreg Clayton //===-- CommandObjectGUI.cpp ------------------------------------*- C++ -*-===//
244d93782SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
644d93782SGreg Clayton //
744d93782SGreg Clayton //===----------------------------------------------------------------------===//
844d93782SGreg Clayton 
944d93782SGreg Clayton #include "CommandObjectGUI.h"
1044d93782SGreg Clayton 
11*7caa17caSRaphael Isemann #include "lldb/Core/IOHandlerCursesGUI.h"
1244d93782SGreg Clayton #include "lldb/Interpreter/CommandInterpreter.h"
1344d93782SGreg Clayton #include "lldb/Interpreter/CommandReturnObject.h"
14b9c1b51eSKate Stone #include "lldb/lldb-private.h"
1544d93782SGreg Clayton 
1644d93782SGreg Clayton using namespace lldb;
1744d93782SGreg Clayton using namespace lldb_private;
1844d93782SGreg Clayton 
1944d93782SGreg Clayton // CommandObjectGUI
2044d93782SGreg Clayton 
21b9c1b51eSKate Stone CommandObjectGUI::CommandObjectGUI(CommandInterpreter &interpreter)
22b9c1b51eSKate Stone     : CommandObjectParsed(interpreter, "gui",
23b9c1b51eSKate Stone                           "Switch into the curses based GUI mode.", "gui") {}
2444d93782SGreg Clayton 
25b9c1b51eSKate Stone CommandObjectGUI::~CommandObjectGUI() {}
2644d93782SGreg Clayton 
27b9c1b51eSKate Stone bool CommandObjectGUI::DoExecute(Args &args, CommandReturnObject &result) {
28914b8d98SDeepak Panickal #ifndef LLDB_DISABLE_CURSES
29b9c1b51eSKate Stone   if (args.GetArgumentCount() == 0) {
3057179860SJonas Devlieghere     Debugger &debugger = GetDebugger();
31456f2712SGreg Clayton 
327ca15ba7SLawrence D'Anna     File &input = debugger.GetInputFile();
33609010d0SLawrence D'Anna     File &output = debugger.GetOutputFile();
34609010d0SLawrence D'Anna     if (input.GetStream() && output.GetStream() && input.GetIsRealTerminal() &&
35609010d0SLawrence D'Anna         input.GetIsInteractive()) {
3644d93782SGreg Clayton       IOHandlerSP io_handler_sp(new IOHandlerCursesGUI(debugger));
3744d93782SGreg Clayton       if (io_handler_sp)
3844d93782SGreg Clayton         debugger.PushIOHandler(io_handler_sp);
3944d93782SGreg Clayton       result.SetStatus(eReturnStatusSuccessFinishResult);
40b9c1b51eSKate Stone     } else {
41456f2712SGreg Clayton       result.AppendError("the gui command requires an interactive terminal.");
42456f2712SGreg Clayton       result.SetStatus(eReturnStatusFailed);
43456f2712SGreg Clayton     }
44b9c1b51eSKate Stone   } else {
4544d93782SGreg Clayton     result.AppendError("the gui command takes no arguments.");
4644d93782SGreg Clayton     result.SetStatus(eReturnStatusFailed);
4744d93782SGreg Clayton   }
4844d93782SGreg Clayton   return true;
49914b8d98SDeepak Panickal #else
50914b8d98SDeepak Panickal   result.AppendError("lldb was not build with gui support");
51914b8d98SDeepak Panickal   return false;
52914b8d98SDeepak Panickal #endif
5344d93782SGreg Clayton }
54