@@ -322,12 +322,87 @@ def delete(task_id: int) -> None:
322322
323323@app .command ()
324324def move (old_id : int , new_id : int ) -> None :
325- """Change task order π """
325+ """Change task position by floating π or sinking β """
326326 settings = Settings ().get_settings ()
327327 if not settings ['tasks' ]:
328328 center_print (
329329 Rule (
330- 'Sorry, cannot move tasks as the Task list is empty' ,
330+ 'Sorry, cannot move task as the Task list is empty' ,
331+ style = error_line_style ,
332+ ),
333+ style = error_text_style ,
334+ )
335+ return
336+
337+ if old_id == new_id :
338+ center_print (
339+ Rule ('No Updates Made' , style = warning_line_style ),
340+ style = warning_text_style ,
341+ )
342+ return
343+
344+ try :
345+ (not 0 <= old_id - 1 < len (settings ['tasks' ])) or (
346+ not 0 <= new_id - 1 < len (settings ['tasks' ])
347+ )
348+ except IndexError :
349+ center_print (
350+ Rule (
351+ 'Are you sure you gave me the correct ID to move?' ,
352+ style = error_line_style ,
353+ ),
354+ style = error_text_style ,
355+ wrap = True ,
356+ )
357+ return
358+
359+ try :
360+ if len (settings ['tasks' ]) == 2 and (
361+ old_id - 1 == len (settings ['tasks' ])
362+ or new_id - 1 == len (settings ['tasks' ])
363+ ):
364+ settings ['tasks' ][old_id - 1 ], settings ['tasks' ][new_id - 1 ] = (
365+ settings ['tasks' ][new_id - 1 ],
366+ settings ['tasks' ][old_id - 1 ],
367+ )
368+ elif old_id < new_id :
369+ for x in range (new_id - 1 , old_id - 1 , - 1 ):
370+ settings ['tasks' ][old_id - 1 ], settings ['tasks' ][x ] = (
371+ settings ['tasks' ][x ],
372+ settings ['tasks' ][old_id - 1 ],
373+ )
374+ else :
375+ for x in range (new_id - 1 , old_id ):
376+ settings ['tasks' ][old_id - 1 ], settings ['tasks' ][x ] = (
377+ settings ['tasks' ][x ],
378+ settings ['tasks' ][old_id - 1 ],
379+ )
380+
381+
382+ Settings ().write_settings (settings )
383+ center_print (
384+ Rule ('Updated Task List' , style = update_line_style ),
385+ style = update_text_style ,
386+ )
387+ print_tasks (settings ['tasks' ])
388+ except Exception :
389+ center_print (
390+ Rule (
391+ "Please check the entered ID's values" , style = error_line_style
392+ ),
393+ style = error_text_style ,
394+ )
395+ print_tasks ()
396+
397+
398+ @app .command ()
399+ def swap (old_id : int , new_id : int ) -> None :
400+ """Swap the positions of two tasks π"""
401+ settings = Settings ().get_settings ()
402+ if not settings ['tasks' ]:
403+ center_print (
404+ Rule (
405+ 'Sorry, cannot swap tasks as the Task list is empty' ,
331406 style = error_line_style ,
332407 ),
333408 style = error_text_style ,
@@ -346,7 +421,7 @@ def move(old_id: int, new_id: int) -> None:
346421 ):
347422 center_print (
348423 Rule (
349- 'Are you sure you gave me the correct ID to delete ?' ,
424+ 'Are you sure you gave me the correct ID to swap ?' ,
350425 style = error_line_style ,
351426 ),
352427 style = error_text_style ,
0 commit comments