 OpenAlpha1 asks, for a tutorial on endcurses based shell scripts are awesome, so we're going to talk about that. So what is endcurses? It's short for new curses and it is a API, a library providing API for programming and it's basically, I've mentioned in the previous video, I didn't call it endcurses, I was referring to dialogue, endcurses is the library that dialogue uses, dialogue is an application that we can make GUI-like applications, dialogues, menus, that sort of thing in our shell. So we're going to go over some of their basic commands today and so let's just dive right into it. So the command is going to be dialogue, which is installed on a lot of systems, not necessarily installed by default, but fairly common installed. If not, it should be in your repositories. So let's go ahead and just make a simple message box. Let's give it a title, so dash dash title and then in quotations what you want to call it, I'll call it my message and then we're going to say, dash dash, it's a message box. That's the type of display that we're doing and we're going to give it its message inside that box. I'll just say hello world and we have to give it a size. So I'm going to say 5 by 20 to start up. So let's go ahead and hit enter and there we go. We got a message box. It says my message there, it says hello world and it has an okay button that I can click with my mouse or hit enter on. And so let's just quickly look at that again. These last two numbers is the height and the width. So if I was to make this five and run it again, you can see it's not wide enough. So you have to make sure that you make your box wide enough for your text, which brings me to the next thing. I'll hit enter to get out of that, control L to clear the screen, bring this back to 20. Let's say I wanted to have a long line of text. I can use backslash n as our new line character and I move the world to the next line, but it's you're not able to see it here because my box is only so many characters high five. But you can see right here it says it was viewing 50% of the message. I can hit my down page and up page to scroll if I need to. But let's go ahead and run that again, but make my height, height of my box 10. And now I can see everything there, no problem. So there's that. So backslash n for new lines, be sure you set the right height and width. If you don't write height, the user can scroll through using down page and up page if your message is extremely long. Let's move on to a new type of box. Let's do a yes or no box. Let's say you want to ask the user yes or no and you want to have a nice little dialogue box. We can say dialogue and again give it a title. I'll just say again my question, question. There we go. And we'll say it's a dash dash yes, no box and we're going to say are you sure? And I'll go with five and 20 here and I'll hit enter and it says are you sure and I have yes no that I can go back and forth with my arrow keys, tab or use my mouse to click. I can click yes or I can click no and you don't see any output, but the program exits with a particular error code, a standard error or standard exit, exit code or escape code. Oh, people are giving me a hard time learning to get that wrong. It's either exit code or escape code, one of the two. I think it's exit, yeah, comment below, people are going to give me a hard time about that. I'm just having a brain fart on that, but how do you check whether they picked yes or no? Well, when you run a command and I went over this in a previous video with our Zennedy videos, I click yes here. You can use the dollar sign or question mark dollar sign to get the exit code or escape code of the last command. So what I can do here is I can say echo or and really in a script you would check the value of this with an if or then statement and here I'll hit echo, question mark, zero indicates that the user chose one. If I run it again and I choose no and I say echo, dollar sign, question mark, it's going to give me an exit code of one. So zero is yes, one is no. So basically as soon as right after you have this dialogue box pop up, you can either save this to a variable in your script or check it immediately and based on whether it's one or zero do something accordingly. Next we're going to create an info box, an info box. So dialogue, let's clear the screen here, dialogue dash dash info box and we'll say this is the info and again we'll give it a size I'll say 10, 25, whatever, it's because I used an exclamation mark there. Let's go ahead and use single coach just to keep things simple. I explained that in a previous video about how exclamation marks are special characters. So there we go. We have an info box. So how is this different than just a regular message box? We can still give it a title. So I can say dash dash title, oops, dash dash title, my title. So it still has a title. What's the difference? There's no okay button. As you can see, we're back at our prompt already. So basically it displays that message and then continues onto the next command. It doesn't wait for a user input. So this is kind of useful if you want to display a message for a certain amount of time. Let's say this is the info, new line, please wait dot dot dot. And then I can issue a new command of sleep for three seconds. So let's just clear the screen and look at this. So we have two commands here. We have our dialogue command which goes up to here and I have a new command for sleep. So we're going to display the message. So it says this is the info, please wait and after three seconds it continues and if it was in a script it would continue with the script. Here it's our last command and it just goes back to our prompt. So that's useful if you just want to display a message for a certain amount of time without any user input and then continue. So next let's look at a text box. So let's say you want to display the text from a file. So let me go ahead and we have some files here from other tutorials, my file dot txt which is just a list of numbers, names and just a few columns here. Let's say we want to display that in a dialogue. Let me go ahead and just say dialogue dash dash text box and then the name of our file in this case my file dot txt and the size I'll make it 20 by 70, just make it kind of big there. And there we go we can display that text. Let's go ahead and just actually vim into that file, my file dot txt and I'll just say just to make it a little extra long just to just demonstrate this I can run the same command here and as you can see it lists all and here we're only looking at 24% so I thought I clicked exit, 24% of the file. So if I was to use my arrow keys I can scroll through this I can use my up and down page to scroll through it jumping by page and I can also click these buttons with my mouse and I can exit when I'm done. So that's one way you can display text maybe you want to display the license like your code is gpl and you want to have a little dialogue that displays the gpl code or other information it's a great way to do it right there. So there are other options with dialogue you can make menus actually let's make a quick menu. Let's go dialogue dash dash menu and then I can say please pick pick one and then I can give it some information here the size of the that I want so I'll say 10 by 30 and then I'm going to say that there's going to be three options and we'll say one is we'll say blue two is green three is pink if I typed everything properly we have a box that we can choose from so if you wanted to get user input but make it something specific so you don't want to have the user type something because they might type something incorrect this forces them to pick one of these options and if I hit enter it goes ahead and here you can see it looks fine right there but the output was the number that we chose which actually brings me I forgot to show you input boxes which I wanted to show you before the menu boxes so I'm gonna say dialogue let's clear the screen again dash dash input box and I can say please enter your name and then I'll say this is 5 by 40 and then I'll just hit enter here and I can type in Chris Chris if I could type my name Chris enter and you can see it outputted Chris right there which isn't very useful right there but you can redirect it into a file or put the output into a variable for example well I could just go like this clear the screen and put this into a file called name so now that's not right let's do to name okay so now I can say Chris enter and I can cut out the file name and it says Chris inside that file we can them into it as well so the reason we had to put the two there was because it's seeing all of this is text and it was taking that standard output and putting it in the file here it's saying don't don't put this into the file just put the exit code into the file or the output of the final output so here let me just explain the command again because I don't feel like I did a good job the first time right in the command dialogue we're saying that we're creating an input box we have a message we can also give it a title to which we didn't do here the size 5 in height 40 in width and then to greater than symbol or you can do to greater than symbols if you want to append to a file and there's no spaces in there and what that will do is that will take the output here and put it into a file so you can take that and store the user's input into a file and the same goes if we go back to our example here where they pick a color one two or three it gave me the output of three here and you can put that into a file or check it check the output there and based on whether they chose one two or three you can do something from there in your script anyway there's a few other things that can do we're not gonna go over but I thought you might find these these useful you may have wondered how to do this this is great because not everyone has a GUI interface you want to write a script with semi GUI a GUI like interface this is great for if you just SSH didn't do any exporting which is tends to be overkill you can still have nice dialogue boxes within your shell script I do thank you for watching I hope that you did enjoy this video and as always I hope that you have a great day if you did enjoy this video think about becoming a supporter over at patreon.com there's a link in the description patreon.com forward there you can become a supporter and get videos early and videos for download and even a dollar a month helps me out greatly so if you appreciate my videos you can show your appreciation with a little bit of money whatever you can spare I do appreciate any appreciation you can show me financially if you can't support me financially be sure to like share subscribe and comment those help out a lot let me know what you think in the comments are you enjoying these videos as always I hope you have a great day