// ao-cli includes an AO client that makes calls to a locla or remote AO server. // The ao-cli client has no store so it makes frequent (hopefully very quick) calls to get exactly the information it needs. // This requires us to make sure the AO API server's REST API is concise and efficient. // The only places ao-cli should call out to an AO server (i.e., use the API in api.js) are in this Use AO menu and in the Tests menu. import { aoEnv } from '../ao-lib/settings.js' import { isLoggedIn, loginPrompt, logout } from './session.js' import { getTopPriorityText } from './priority.js' import { AO_DEFAULT_HOSTNAME } from '../ao-lib/api.js' import { headerStyle } from './styles.js' import { cardMenu } from './cards.js' import { connectMenu } from './connect.js' import chatMenu from './shadowchat.js' import { promptMenu } from './welcome.js' // Prints the Use AO Menu and executes the user's choice. Using the AO as a client occurs only under this menu item (except Tests menu). export default async function useAoMenu() { const loggedIn = isLoggedIn() if(loggedIn) { console.log('Logged in as:', aoEnv('AO_CLI_SESSION_USERNAME')) const topPriority = await getTopPriorityText() if(topPriority) { console.log('Top priority:', topPriority) } else { console.log('Error contacting server, is your AO server running? AO features might not work.') } } let aoMenuChoices = [] if(loggedIn) { aoMenuChoices.push( 'Deck', 'Chat', 'P2P', ) } aoMenuChoices.push( loggedIn ? 'Log Out' : 'Log In', 'Back to Main Menu' ) const answer = await promptMenu(aoMenuChoices, 'AO', 'connect to an AO server to use AO features') switch(answer) { case 'Deck': //await todoList('My Todo List', ['Add full AO install process to ao-cli in convenient format', 'Add AO server unit tests to ao-cli', 'Get groceries', 'Play music every day']) while(await cardMenu()) {} break case 'P2P': while(await connectMenu()) {} break case 'Chat': while(await chatMenu()) {} break case 'Log In': console.log('\nao-cli will use the AO API to log into the AO server at', (aoEnv('AO_CLI_TARGET_HOSTNAME') || AO_DEFAULT_HOSTNAME) + '.') await loginPrompt() break case 'Log Out': await logout() //await spinnerWait('Logging out...') break default: return false } return true }