summaryrefslogtreecommitdiff
path: root/gptcurses.h
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2011-09-10 20:29:53 -0400
committersrs5694 <srs5694@users.sourceforge.net>2011-09-10 20:29:53 -0400
commit3860cbe1cafb88d70097bdfb8d84cc0029f1738e (patch)
tree337b424babd62ef8fb5d124111f62bb436c92186 /gptcurses.h
parent00b6d7a4604e759eb3c92b3ecea608d6fe024b81 (diff)
downloadsgdisk-3860cbe1cafb88d70097bdfb8d84cc0029f1738e.tar.gz
New files in support of version 0.8.0
Diffstat (limited to 'gptcurses.h')
-rw-r--r--gptcurses.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/gptcurses.h b/gptcurses.h
new file mode 100644
index 0000000..14f43ad
--- /dev/null
+++ b/gptcurses.h
@@ -0,0 +1,129 @@
+/*
+ * Implementation of GPTData class derivative with curses-based text-mode
+ * interaction
+ * Copyright (C) 2011 Roderick W. Smith
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <iostream>
+#include <string>
+#include "gptpart.h"
+#include "gpt.h"
+
+#ifndef __GPT_CURSES
+#define __GPT_CURSES
+
+using namespace std;
+
+struct MenuItem {
+ int key; // Keyboard shortcut
+ string name; // Item name; 8 characters
+ string desc; // Description
+};
+
+static struct MenuItem menuMain[] = {
+ { 'a', "Align ", "Set partition alignment policy" },
+ { 'b', "Backup", "Back up the partition table" },
+ { 'd', "Delete", "Delete the current partition" },
+ { 'h', " Help ", "Print help screen" },
+ { 'i', " Info ", "Display information about the partition" },
+ { 'l', " Load ", "Load partition table backup from file" },
+ { 'm', " naMe ", "Change the partition's name" },
+ { 'n', " New ", "Create new partition from free space" },
+ { 'q', " Quit ", "Quit program without writing partition table" },
+ { 't', " Type ", "Change the filesystem type code GUID" },
+ { 'v', "Verify", "Verify the integrity of the disk's data structures" },
+ { 'w', "Write ", "Write partition table to disk (this might destroy data)" },
+ { 0, "", "" }
+};
+
+#define EMPTY_SPACE_OPTIONS "abhlnqvw"
+#define PARTITION_OPTIONS "abdhilmqtvw"
+
+
+// A "Space" is a partition or an unallocated chunk of disk space, maintained
+// in a doubly-linked-list data structure to facilitate creating displays of
+// partitions and unallocated chunks of space on the disk in the main
+// cgdisk partition list. This list MUST be correctly maintained and in order,
+// and the numSpaces variable in the main GPTDataCurses class must specify
+// how many Spaces are in the main linked list of Spaces.
+struct Space {
+ uint64_t firstLBA;
+ uint64_t lastLBA;
+ GPTPart *origPart;
+ int partNum;
+ Space *nextSpace;
+ Space *prevSpace;
+};
+
+class GPTDataCurses : public GPTData {
+protected:
+ static int numInstances;
+ GPTPart emptySpace;
+ Space *firstSpace;
+ Space *lastSpace;
+ Space *currentSpace;
+ int currentSpaceNum;
+ string whichOptions;
+ char currentKey;
+ int numSpaces;
+ // Functions relating to Spaces data structures
+ void EmptySpaces(void);
+ int MakeSpacesFromParts(void);
+ void AddEmptySpace(uint64_t firstLBA, uint64_t lastLBA);
+ int AddEmptySpaces(void);
+ void UnlinkSpace(Space *theSpace);
+ void LinkToEnd(Space *theSpace);
+ void SortSpaces(void);
+ void IdentifySpaces(void);
+ // Data display functions
+ Space* ShowSpace(int spaceNum, int lineNum);
+ int DisplayParts(int selected);
+public:
+ GPTDataCurses(void);
+ ~GPTDataCurses(void);
+ // Functions corresponding to main menu items
+ void DeletePartition(int partNum);
+ void ShowInfo(int partNum);
+ void ChangeName(int partNum);
+ void ChangeType(int partNum);
+ void SetAlignment(void);
+ void Verify(void);
+ void MakeNewPart(void);
+ void SaveData(void);
+ void Backup(void);
+ void LoadBackup(void);
+ void ShowHelp(void);
+ // User input and menuing functions
+ void ChangeSpaceSelection(int delta);
+ void MoveSelection(int delta);
+ void DisplayOptions(char selectedKey);
+ void AcceptInput();
+ int Dispatch(char operation);
+ void DrawMenu(void);
+ int MainMenu(void);
+}; // class GPTDataCurses
+
+// Non-class support functions (mostly to do simple curses stuff)....
+
+void ClearLine(int lineNum);
+void ClearBottom(void);
+void PromptToContinue(void);
+void Report(string theText);
+void ShowTypes(void);
+
+#endif